|
1 | 1 | import { beforeEach, describe, expect, test, xtest } from '@jest/globals';
|
2 | 2 | import { GradeSchool } from './grade-school';
|
3 | 3 |
|
4 |
| -describe('School', () => { |
| 4 | +describe('Grade School', () => { |
5 | 5 | let school;
|
6 | 6 |
|
7 | 7 | beforeEach(() => {
|
8 | 8 | school = new GradeSchool();
|
9 | 9 | });
|
10 | 10 |
|
11 |
| - test('a new school has an empty roster', () => { |
12 |
| - expect(school.roster()).toEqual({}); |
| 11 | + test('Roster is empty when no student is added', () => { |
| 12 | + expect(school.roster()).toEqual([]); |
13 | 13 | });
|
14 | 14 |
|
15 |
| - xtest('adding a student adds them to the roster for the given grade', () => { |
| 15 | + xtest('Add a student', () => { |
| 16 | + expect(school.add('Aimee', 2)).toEqual(true); |
| 17 | + }); |
| 18 | + |
| 19 | + xtest('Student is added to the roster', () => { |
16 | 20 | school.add('Aimee', 2);
|
17 | 21 |
|
18 |
| - const expectedDb = { 2: ['Aimee'] }; |
| 22 | + const expectedDb = ['Aimee']; |
19 | 23 | expect(school.roster()).toEqual(expectedDb);
|
20 | 24 | });
|
21 | 25 |
|
22 |
| - xtest('adding more students to the same grade adds them to the roster', () => { |
| 26 | + xtest('Adding multiple students in the same grade in the roster', () => { |
| 27 | + expect(school.add('Blair', 2)).toEqual(true); |
| 28 | + expect(school.add('James', 2)).toEqual(true); |
| 29 | + expect(school.add('Paul', 2)).toEqual(true); |
| 30 | + }); |
| 31 | + |
| 32 | + xtest('Multiple students in the same grade are added to the roster', () => { |
23 | 33 | school.add('Blair', 2);
|
24 | 34 | school.add('James', 2);
|
25 | 35 | school.add('Paul', 2);
|
26 | 36 |
|
27 |
| - const expectedDb = { 2: ['Blair', 'James', 'Paul'] }; |
| 37 | + const expectedDb = ['Blair', 'James', 'Paul']; |
28 | 38 | expect(school.roster()).toEqual(expectedDb);
|
29 | 39 | });
|
30 | 40 |
|
31 |
| - xtest('adding students to different grades adds them to the roster', () => { |
| 41 | + xtest('Cannot add student to same grade in the roster more than once', () => { |
| 42 | + expect(school.add('Blair', 2)).toEqual(true); |
| 43 | + expect(school.add('James', 2)).toEqual(true); |
| 44 | + expect(school.add('James', 2)).toEqual(false); |
| 45 | + expect(school.add('Paul', 2)).toEqual(true); |
| 46 | + }); |
| 47 | + |
| 48 | + xtest('Student not added to same grade in the roster more than once', () => { |
| 49 | + school.add('Blair', 2); |
| 50 | + school.add('James', 2); |
| 51 | + school.add('James', 2); |
| 52 | + school.add('Paul', 2); |
| 53 | + |
| 54 | + const expectedDb = ['Blair', 'James', 'Paul']; |
| 55 | + expect(school.roster()).toEqual(expectedDb); |
| 56 | + }); |
| 57 | + |
| 58 | + xtest('Adding students in multiple grades', () => { |
| 59 | + expect(school.add('Chelsea', 3)).toEqual(true); |
| 60 | + expect(school.add('Logan', 7)).toEqual(true); |
| 61 | + }); |
| 62 | + |
| 63 | + xtest('Students in multiple grades are added to the roster', () => { |
32 | 64 | school.add('Chelsea', 3);
|
33 | 65 | school.add('Logan', 7);
|
34 | 66 |
|
35 |
| - const expectedDb = { 3: ['Chelsea'], 7: ['Logan'] }; |
| 67 | + const expectedDb = ['Chelsea', 'Logan']; |
36 | 68 | expect(school.roster()).toEqual(expectedDb);
|
37 | 69 | });
|
38 | 70 |
|
39 |
| - xtest('grade returns the students in that grade in alphabetical order', () => { |
40 |
| - school.add('Franklin', 5); |
41 |
| - school.add('Bradley', 5); |
42 |
| - school.add('Jeff', 1); |
43 |
| - |
44 |
| - const expectedStudents = ['Bradley', 'Franklin']; |
45 |
| - expect(school.grade(5)).toEqual(expectedStudents); |
| 71 | + xtest('Cannot add same student to multiple grades in the roster', () => { |
| 72 | + expect(school.add('Blair', 2)).toEqual(true); |
| 73 | + expect(school.add('James', 2)).toEqual(true); |
| 74 | + expect(school.add('James', 3)).toEqual(false); |
| 75 | + expect(school.add('Paul', 3)).toEqual(true); |
46 | 76 | });
|
47 | 77 |
|
48 |
| - xtest('grade returns an empty array if there are no students in that grade', () => { |
49 |
| - expect(school.grade(1)).toEqual([]); |
| 78 | + xtest('Student not added to multiple grades in the roster', () => { |
| 79 | + school.add('Blair', 2); |
| 80 | + school.add('James', 2); |
| 81 | + school.add('James', 3); |
| 82 | + school.add('Paul', 3); |
| 83 | + |
| 84 | + const expectedDb = ['Blair', 'James', 'Paul']; |
| 85 | + expect(school.roster()).toEqual(expectedDb); |
50 | 86 | });
|
51 | 87 |
|
52 |
| - xtest('the students names in each grade in the roster are sorted', () => { |
53 |
| - school.add('Jennifer', 4); |
54 |
| - school.add('Kareem', 6); |
55 |
| - school.add('Christopher', 4); |
56 |
| - school.add('Kyle', 3); |
| 88 | + xtest('Students are sorted by grades in the roster', () => { |
| 89 | + school.add('Jim', 3); |
| 90 | + school.add('Peter', 2); |
| 91 | + school.add('Anna', 1); |
57 | 92 |
|
58 |
| - const expectedSortedStudents = { |
59 |
| - 3: ['Kyle'], |
60 |
| - 4: ['Christopher', 'Jennifer'], |
61 |
| - 6: ['Kareem'], |
62 |
| - }; |
63 |
| - expect(school.roster()).toEqual(expectedSortedStudents); |
| 93 | + const expectedDb = ['Anna', 'Peter', 'Jim']; |
| 94 | + expect(school.roster()).toEqual(expectedDb); |
64 | 95 | });
|
65 | 96 |
|
66 |
| - xtest('roster cannot be modified outside of module', () => { |
67 |
| - school.add('Aimee', 2); |
68 |
| - const roster = school.roster(); |
69 |
| - roster[2].push('Oops.'); |
70 |
| - const expectedDb = { 2: ['Aimee'] }; |
| 97 | + xtest('Students are sorted by name in the roster', () => { |
| 98 | + school.add('Peter', 2); |
| 99 | + school.add('Zoe', 2); |
| 100 | + school.add('Alex', 2); |
| 101 | + |
| 102 | + const expectedDb = ['Alex', 'Peter', 'Zoe']; |
71 | 103 | expect(school.roster()).toEqual(expectedDb);
|
72 | 104 | });
|
73 | 105 |
|
74 |
| - xtest('roster cannot be modified outside of module using grade()', () => { |
75 |
| - school.add('Aimee', 2); |
76 |
| - school.grade(2).push('Oops.'); |
77 |
| - const expectedDb = { 2: ['Aimee'] }; |
| 106 | + xtest('Students are sorted by grades and then by name in the roster', () => { |
| 107 | + school.add('Peter', 2); |
| 108 | + school.add('Anna', 1); |
| 109 | + school.add('Barb', 1); |
| 110 | + school.add('Zoe', 2); |
| 111 | + school.add('Alex', 2); |
| 112 | + school.add('Jim', 3); |
| 113 | + school.add('Charlie', 1); |
| 114 | + |
| 115 | + const expectedDb = [ |
| 116 | + 'Anna', |
| 117 | + 'Barb', |
| 118 | + 'Charlie', |
| 119 | + 'Alex', |
| 120 | + 'Peter', |
| 121 | + 'Zoe', |
| 122 | + 'Jim', |
| 123 | + ]; |
78 | 124 | expect(school.roster()).toEqual(expectedDb);
|
79 | 125 | });
|
80 | 126 |
|
81 |
| - xtest("a student can't be in two different grades", () => { |
82 |
| - school.add('Aimee', 2); |
83 |
| - school.add('Aimee', 1); |
| 127 | + xtest('Grade is empty if no students in the roster', () => { |
| 128 | + expect(school.grade(1)).toEqual([]); |
| 129 | + }); |
| 130 | + |
| 131 | + xtest('Grade is empty if no students in that grade', () => { |
| 132 | + school.add('Peter', 2); |
| 133 | + school.add('Zoe', 2); |
| 134 | + school.add('Alex', 2); |
| 135 | + school.add('Jim', 3); |
| 136 | + |
| 137 | + expect(school.grade(1)).toEqual([]); |
| 138 | + }); |
| 139 | + |
| 140 | + xtest('Student not added to same grade more than once', () => { |
| 141 | + school.add('Blair', 2); |
| 142 | + school.add('James', 2); |
| 143 | + school.add('James', 2); |
| 144 | + school.add('Paul', 2); |
| 145 | + |
| 146 | + const expectedDb = ['Blair', 'James', 'Paul']; |
| 147 | + expect(school.grade(2)).toEqual(expectedDb); |
| 148 | + }); |
| 149 | + |
| 150 | + xtest('Student not added to multiple grades', () => { |
| 151 | + school.add('Blair', 2); |
| 152 | + school.add('James', 2); |
| 153 | + school.add('James', 3); |
| 154 | + school.add('Paul', 3); |
| 155 | + |
| 156 | + const expectedDb = ['Blair', 'James']; |
| 157 | + expect(school.grade(2)).toEqual(expectedDb); |
| 158 | + }); |
| 159 | + |
| 160 | + xtest('Student not added to other grade for multiple grades', () => { |
| 161 | + school.add('Blair', 2); |
| 162 | + school.add('James', 2); |
| 163 | + school.add('James', 3); |
| 164 | + school.add('Paul', 3); |
| 165 | + |
| 166 | + const expectedDb = ['Paul']; |
| 167 | + expect(school.grade(3)).toEqual(expectedDb); |
| 168 | + }); |
| 169 | + |
| 170 | + xtest('Students are sorted by name in a grade', () => { |
| 171 | + school.add('Franklin', 5); |
| 172 | + school.add('Bradley', 5); |
| 173 | + school.add('Jeff', 1); |
84 | 174 |
|
85 |
| - expect(school.grade(2)).toEqual([]); |
| 175 | + const expectedDb = ['Bradley', 'Franklin']; |
| 176 | + expect(school.grade(5)).toEqual(expectedDb); |
86 | 177 | });
|
87 | 178 | });
|
0 commit comments