-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
grade-school_test.php
70 lines (58 loc) · 1.82 KB
/
grade-school_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
<?php
require "grade-school.php";
use PHPUnit\Framework\TestCase;
class GradeSchoolTest extends TestCase
{
protected $school ;
protected function setUp()
{
$this->school = new School() ;
}
public function testNoStudent()
{
$this->assertEquals(0, $this->school->numberOfStudents());
}
public function testAddStudent()
{
$this->school->add("Claire", 2);
$this->assertContains('Claire', $this->school->grade(2));
}
public function testAddStudentsInSameGrade()
{
$this->school->add("Marc", 2);
$this->school->add("Virginie", 2);
$this->school->add("Claire", 2);
$students = $this->school->grade(2) ;
$this->assertCount(3, $students);
$this->assertEqualsCanonicalizing(
['Claire', 'Marc', 'Virginie'],
$students
);
}
public function testAddStudentInDifferentGrades()
{
$this->school->add("Marc", 3);
$this->school->add("Claire", 6);
$this->assertContains('Marc', $this->school->grade(3));
$this->assertContains('Claire', $this->school->grade(6));
$this->assertNotContains('Marc', $this->school->grade(6));
$this->assertNotContains('Claire', $this->school->grade(3));
}
public function testEmptyGrade()
{
$this->assertEmpty($this->school->grade(1));
}
public function testSortSchool()
{
$this->school->add("Marc", 5);
$this->school->add("Virginie", 5);
$this->school->add("Claire", 5);
$this->school->add("Mehdi", 4);
$sortedStudents = [
4 => ['Mehdi'],
5 => ['Claire', 'Marc', 'Virginie']
];
$schoolStudents = $this->school->studentsByGradeAlphabetical() ;
$this->assertEquals($sortedStudents, $schoolStudents) ;
}
}