
The way Wagic tests Magic cards is very simple and easy to understand. The tests are in plain text which makes the tests probably shorter than if they were coded in C++ which is the language that Wagic uses.
The tests consist of an init section, init is short for initialization or beginning, a do section which plays a card, and the assert section which checks to make sure that the card did what it was supposed to do.
I don’t usually cut and paste anything but the blog does a good job describing the parts of the test.
Wagic Blog
Wagic Card Testing
INIT
When it loads a test file, the Testing Suite initializes the game with the data from the initial state. So for example:
[INIT]
FIRSTMAIN
[PLAYER1]
hand:Ancestor’s Chosen
graveyard:swamp,grizzly bears,dragon engine
manapool:{5}{W}{W}
[PLAYER2]
graveyard:black knight
The above init state is loaded by the testing suite. The Game engine is “forced” to go to the “first main phase” of player 1. Player 1 has {5}{W}{W} in his manapool, Ancestor’s Chosen in his hand, and 3 cards in his graveyard. Player 2 has 1 card in his graveyard. Obviously what we want to test here is Ancestor’s Chosen ability: When Ancestor’s Chosen comes into play, you gain 1 life for each card in your graveyard. The obvious advantage is that I don’t have to create a specific deck with Ancestor’s Chosen to playtest it in order to test its ability.
DO
As I said in my other article, the testing suite is like a CPU player, except it is very dumb: Instead of computing the best moves for its cards, it just takes orders from the test file. This is the second part of the test file for Ancestor’s Chosen:
[DO]
Ancestor’s Chosen
It looks simple? Well it is. What I tell the “dumb AI player” here is: just click on the Ancestor’s Chosen card. And that’s it. Since player 1 has the mana in its mana pool, and it’s his first main phase, clicking on the ancestor’s chosen card will put it into play.
ASSERT
Now that we’ve done the actions needed in the test, what we want is to compare the new state of the Game, with what we expect to happen. We write what we expect to happen in the third part of the test file:
[ASSERT]
FIRSTMAIN
[PLAYER1]
inplay:Ancestor’s Chosen
life:23
graveyard:swamp,grizzly bears,dragon engine
manapool:{0}
[PLAYER2]
graveyard:black knight
[END]
So, if you compare this to the initial state we described above, the differences are the following: Ancestor’s Chosen is in play, player 1 has no more left mana in his manapool, and he has 23 life (initial life of player 1 wasn’t described in the initial state. In that case the game uses the default value of 20).
Now, this is what the test expects to happen. The testing suite will of course compare this to the actual state of the game. If the expected and the actual states are not equivalent, then the test fails and the program lets me know about the error.
Here is the full test file for Ancestor’s Chosen:
#Testing Ancestors chosen
[INIT]
FIRSTMAIN
[PLAYER1]
hand:Ancestor’s Chosen
graveyard:swamp,grizzly bears,dragon engine
manapool:{5}{W}{W}
[PLAYER2]
graveyard:black knight
[DO]
Ancestor’s Chosen
[ASSERT]
FIRSTMAIN
[PLAYER1]
inplay:Ancestor’s Chosen
life:23
graveyard:swamp,grizzly bears,dragon engine
manapool:{0}
[PLAYER2]
graveyard:black knight
[END]