Vi scrivo qui itest da implementare e far passare
obbligatoriamente per ogni task.
Task 1
Codice:
void testEngineCreation()
{
Engine engine = new Engine(800, 600);
assertTrue(engine.IsCreated(), "Engine has not been created correctly");
}
void testDisplaySize()
{
Engine engine = new Engine(800, 600);
assertAreEqual(800, engine.getDisplayWidth(), "Display width must be 800");
assertAreEqual(600, engine.getDisplayHeight(), "Display height must be 600");
}
void testEngineShutdown()
{
Engine engine = new Engine(800, 600);
engine.shutDown();
assertTrue(engine.IsCreated(), "Engine has not shut down correctly");
}
Task 2
Da definire.
Task 3
Codice:
void testAudioCreation()
{
Audio audio = new Audio();
assertTrue(audio.IsInitialised(), "Audio has not been initialised correctly");
}
void testAudioShutdown()
{
Audio audio = new Audio();
engine.shutDown();
assertTrue(audio.IsCreated(), "Audio has not shut down correctly");
}
Task 4
Codice:
void testLoadDiamondTexture()
{
Texture texture = new Texture("diamond");
assertTrue(texture.isLoaded(), "texture has not been loaded");
}
void testSize()
{
Texture texture = new Texture("diamond");
assertEqual(64, texture.getWidth(), "texture width is wrong");
assertEqual(64, texture.getHeight(), "texture width is wrong");
}
void testLoadFailed()
{
try
{
Texture texture = new Texture("this_texture_doesnt_exist");
}
catch (TextureNotFoundException)
{
return;
}
assertFail();
}
Task 5
Qui serve un mock, ma primo devo dirvi che cos'e' un mock. Scrivo i test in seguito.
Task 6
Codice:
void testSound()
{
Sound sound = new Sound("diamond");
assertTrue(sound.isLoaded(), "sound has not been loaded");
}
void testLoadSoundFailed()
{
try
{
Sound sound = new sound("this_sound_doesnt_exist");
}
catch (TextureNotFoundException)
{
return;
}
assertFail();
}
void testPlaySound()
{
Sound sound = new Sound("diamond");
sound.play();
assertTrue(sound.isPlayed(), "sound has not been played");
}
Anche testPlaySound() andrebbe implementato con un mock object. Cosi' non e' molto utile e non vogliamo che i test riproducano effettivamente il suono ogni volta che sono eseguiti. Vedremo in seguito come risolvere il problema.
Non ho compilato i test, ci saranno sicuramente errori di sintassi e magari non sara' proprio Java, ma servono per darvi l'idea dei test che ho bisogno che implementiate.
Ricordate:
Il task non e' completo se questi test non passano.
Implementate solo il codice che serve per far passare questi test. Siete caldamente invitati a scrivere altri test che servano per testare il codice che state scrivendo per far passare questi test.
I nomi delle classi che uso nei test e' "abbastanza" obbligatorio. E' un esempio di come vi dettero' l'architettura del gioco attraverso i test e non attraverso un documento.
Se vedete duplicazioni nei test (e ci sono), siete invitati ad eliminarle usando le feature di JUnit.
Infine, questi test lasciano dei buchi, come il clear dello schermo. Alcune cose non sono facili da testare automaticamente, soprattutto quando c'e' di mezzo la presentazione a video. Vedremo in seguito come possiamo risolvere anche questo problema. Per ora abbiamo qualche test e qualche test e' sempre meglio di nessun test.