|
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']; |
| 23 | + expect(school.roster()).toEqual(expectedDb); |
| 24 | + }); |
| 25 | + |
| 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', () => { |
| 33 | + school.add('Blair', 2); |
| 34 | + school.add('James', 2); |
| 35 | + school.add('Paul', 2); |
| 36 | + |
| 37 | + const expectedDb = ['Blair', 'James', 'Paul']; |
19 | 38 | expect(school.roster()).toEqual(expectedDb); |
20 | 39 | }); |
21 | 40 |
|
22 | | - xtest('adding more students to the same grade 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', () => { |
23 | 49 | school.add('Blair', 2); |
24 | 50 | school.add('James', 2); |
| 51 | + school.add('James', 2); |
25 | 52 | school.add('Paul', 2); |
26 | 53 |
|
27 | | - const expectedDb = { 2: ['Blair', 'James', 'Paul'] }; |
| 54 | + const expectedDb = ['Blair', 'James', 'Paul']; |
28 | 55 | expect(school.roster()).toEqual(expectedDb); |
29 | 56 | }); |
30 | 57 |
|
31 | | - xtest('adding students to different grades adds them to the roster', () => { |
| 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); |
| 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); |
| 76 | + }); |
| 77 | + |
| 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); |
43 | 83 |
|
44 | | - const expectedStudents = ['Bradley', 'Franklin']; |
45 | | - expect(school.grade(5)).toEqual(expectedStudents); |
| 84 | + const expectedDb = ['Blair', 'James', 'Paul']; |
| 85 | + expect(school.roster()).toEqual(expectedDb); |
| 86 | + }); |
| 87 | + |
| 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); |
| 92 | + |
| 93 | + const expectedDb = ['Anna', 'Peter', 'Jim']; |
| 94 | + expect(school.roster()).toEqual(expectedDb); |
46 | 95 | }); |
47 | 96 |
|
48 | | - xtest('grade returns an empty array if there are no students in that grade', () => { |
| 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']; |
| 103 | + expect(school.roster()).toEqual(expectedDb); |
| 104 | + }); |
| 105 | + |
| 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 = ["Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim"]; |
| 116 | + expect(school.roster()).toEqual(expectedDb); |
| 117 | + }); |
| 118 | + |
| 119 | + xtest('Grade is empty if no students in the roster', () => { |
49 | 120 | expect(school.grade(1)).toEqual([]); |
50 | 121 | }); |
51 | 122 |
|
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); |
| 123 | + xtest('Grade is empty if no students in that grade', () => { |
| 124 | + school.add("Peter", 2); |
| 125 | + school.add("Zoe", 2); |
| 126 | + school.add("Alex", 2); |
| 127 | + school.add("Jim", 3); |
57 | 128 |
|
58 | | - const expectedSortedStudents = { |
59 | | - 3: ['Kyle'], |
60 | | - 4: ['Christopher', 'Jennifer'], |
61 | | - 6: ['Kareem'], |
62 | | - }; |
63 | | - expect(school.roster()).toEqual(expectedSortedStudents); |
| 129 | + expect(school.grade(1)).toEqual([]); |
64 | 130 | }); |
65 | 131 |
|
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'] }; |
71 | | - expect(school.roster()).toEqual(expectedDb); |
| 132 | + xtest('Student not added to same grade more than once', () => { |
| 133 | + school.add('Blair', 2); |
| 134 | + school.add('James', 2); |
| 135 | + school.add('James', 2); |
| 136 | + school.add('Paul', 2); |
| 137 | + |
| 138 | + const expectedDb = ['Blair', 'James', 'Paul']; |
| 139 | + expect(school.grade(2)).toEqual(expectedDb); |
72 | 140 | }); |
73 | 141 |
|
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'] }; |
78 | | - expect(school.roster()).toEqual(expectedDb); |
| 142 | + xtest('Student not added to multiple grades', () => { |
| 143 | + school.add('Blair', 2); |
| 144 | + school.add('James', 2); |
| 145 | + school.add('James', 3); |
| 146 | + school.add('Paul', 3); |
| 147 | + |
| 148 | + const expectedDb = ['Blair', 'James']; |
| 149 | + expect(school.grade(2)).toEqual(expectedDb); |
79 | 150 | }); |
80 | 151 |
|
81 | | - xtest("a student can't be in two different grades", () => { |
82 | | - school.add('Aimee', 2); |
83 | | - school.add('Aimee', 1); |
| 152 | + xtest('Student not added to other grade for multiple grades', () => { |
| 153 | + school.add('Blair', 2); |
| 154 | + school.add('James', 2); |
| 155 | + school.add('James', 3); |
| 156 | + school.add('Paul', 3); |
| 157 | + |
| 158 | + const expectedDb = ['Paul']; |
| 159 | + expect(school.grade(3)).toEqual(expectedDb); |
| 160 | + }); |
| 161 | + |
| 162 | + xtest('Students are sorted by name in a grade', () => { |
| 163 | + school.add('Franklin', 5); |
| 164 | + school.add('Bradley', 5); |
| 165 | + school.add('Jeff', 1); |
84 | 166 |
|
85 | | - expect(school.grade(2)).toEqual([]); |
| 167 | + const expectedDb = ['Bradley', 'Franklin']; |
| 168 | + expect(school.grade(5)).toEqual(expectedDb); |
86 | 169 | }); |
87 | 170 | }); |
0 commit comments