-
Notifications
You must be signed in to change notification settings - Fork 0
/
foostable.test.php
72 lines (61 loc) · 2.79 KB
/
foostable.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
require_once(dirname(__FILE__) . '/simpletest/autorun.php');
require_once('foos.class.php');
class TestFoosTable extends UnitTestCase {
function testSort1() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$table->calculateScore();
//print_r($table->getPlayers());
$this->assertEqual($table->getPlayerAtPosition(1), $table->getPlayerByName('coffey'));
$this->assertEqual($table->getPositionOfPlayer('samuel'), 3);
$this->assertEqual($table->getPlayerByName('marek')->getGames(), 11);
}
function testSave() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$table->calculateScore();
$table->saveToFile('games2.json');
$file = file_get_contents(dirname(__FILE__) . '/testData/games.json');
$file2 = file_get_contents(dirname(__FILE__) . '/testData/games2.json');
$this->assertEqual($file, $file2);
}
function testLostAgainst() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$table->calculateScore();
$lostAgainst = $table->getPlayerByName('marek')->getLostAgainstList();
$this->assertEqual($lostAgainst['COFFEY']['count'], 2);
$this->assertEqual($lostAgainst['COFFEY']['player'], $table->getPlayerByName('coffey'));
$this->assertEqual(count($lostAgainst), 6);
$nemesis = $table->getPlayerByName('michaelhoran')->getNemesis();
$this->assertEqual($nemesis['count'], 2);
$this->assertEqual($nemesis['player'], $table->getPlayerByName('jing'));
}
function testLastTimestamp() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$table->calculateScore();
$this->assertEqual($table->getPlayerByName('marek')->getLastTimestamp(), 1328033408);
}
function testDeleteMatch() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$matches = $table->getMatches();
$match = $matches[3];
$this->assertEqual($table->getNumberOfMatches(), 37);
$this->assertTrue($table->deleteMatch($match->getTimestamp()));
$this->assertEqual($table->getNumberOfMatches(), 36);
$this->assertFalse($table->deleteMatch($match->getTimestamp()));
$this->assertEqual($table->getNumberOfMatches(), 36);
}
function testLog() {
$table = new FoosTable(dirname(__FILE__) . '/testData/');
$table->loadCurrentStatus();
$table->setLogMaxSize(15);
$table->calculateScore();
$log = $table->getLog();
$this->assertEqual(count($log), 15);
$this->assertEqual(count($log[0]), 11);
}
}