|
1 | 1 | local School = require('grade-school')
|
2 | 2 |
|
3 | 3 | describe('grade-school', function()
|
4 |
| - it('a new school has an empty roster', function() |
| 4 | + it('roster is empty when no student is added', function() |
5 | 5 | local school = School:new()
|
6 |
| - local expected = {} |
7 |
| - local result = school:roster() |
8 |
| - assert.are.same(expected, result) |
| 6 | + assert.are.same({}, school:roster()) |
9 | 7 | end)
|
10 | 8 |
|
11 |
| - it('adding a student adds them to the roster for the given grade', function() |
| 9 | + it('add a student', function() |
| 10 | + local school = School:new() |
| 11 | + assert.is_true(school:add('Aimee', 2)) |
| 12 | + end) |
| 13 | + |
| 14 | + it('student is added to the roster', function() |
12 | 15 | local school = School:new()
|
13 | 16 | school:add('Aimee', 2)
|
14 |
| - local expected = { [2] = { 'Aimee' } } |
15 |
| - local result = school:roster() |
16 |
| - assert.are.same(expected, result) |
| 17 | + assert.are.same({ 'Aimee' }, school:roster()) |
| 18 | + end) |
| 19 | + |
| 20 | + it('adding multiple students in the same grade in the roster', function() |
| 21 | + local school = School:new() |
| 22 | + assert.is_true(school:add('Blair', 2)) |
| 23 | + assert.is_true(school:add('James', 2)) |
| 24 | + assert.is_true(school:add('Paul', 2)) |
| 25 | + end) |
| 26 | + |
| 27 | + it('multiple students in the same grade are added to the roster', function() |
| 28 | + local school = School:new() |
| 29 | + school:add('Blair', 2) |
| 30 | + school:add('James', 2) |
| 31 | + school:add('Paul', 2) |
| 32 | + assert.are.same({ 'Blair', 'James', 'Paul' }, school:roster()) |
| 33 | + end) |
| 34 | + |
| 35 | + it('cannot add student to same grade in the roster more than once', function() |
| 36 | + local school = School:new() |
| 37 | + assert.is_true(school:add('Blair', 2)) |
| 38 | + assert.is_true(school:add('James', 2)) |
| 39 | + assert.is_false(school:add('James', 2)) |
| 40 | + assert.is_true(school:add('Paul', 2)) |
17 | 41 | end)
|
18 | 42 |
|
19 |
| - it('adding more students to the same grade adds them to the roster', function() |
| 43 | + it('student not added to same grade in the roster more than once', function() |
20 | 44 | local school = School:new()
|
21 | 45 | school:add('Blair', 2)
|
22 | 46 | school:add('James', 2)
|
| 47 | + school:add('James', 2) |
23 | 48 | school:add('Paul', 2)
|
24 |
| - local expected = { [2] = { 'Blair', 'James', 'Paul' } } |
25 |
| - local result = school:roster() |
26 |
| - assert.are.same(expected, result) |
| 49 | + assert.are.same({ 'Blair', 'James', 'Paul' }, school:roster()) |
| 50 | + end) |
| 51 | + |
| 52 | + it('adding students in multiple grades', function() |
| 53 | + local school = School:new() |
| 54 | + assert.is_true(school:add('Chelsea', 3)) |
| 55 | + assert.is_true(school:add('Logan', 7)) |
27 | 56 | end)
|
28 | 57 |
|
29 |
| - it('adding students to different grades adds them to the roster', function() |
| 58 | + it('students in multiple grades are added to the roster', function() |
30 | 59 | local school = School:new()
|
31 | 60 | school:add('Chelsea', 3)
|
32 | 61 | school:add('Logan', 7)
|
33 |
| - local expected = { [3] = { 'Chelsea' }, [7] = { 'Logan' } } |
34 |
| - local result = school:roster() |
35 |
| - assert.are.same(expected, result) |
| 62 | + assert.are.same({ 'Chelsea', 'Logan' }, school:roster()) |
36 | 63 | end)
|
37 | 64 |
|
38 |
| - it('grade returns the students in that grade in alphabetical order', function() |
| 65 | + it('cannot add same student to multiple grades in the roster', function() |
39 | 66 | local school = School:new()
|
40 |
| - school:add('Franklin', 5) |
41 |
| - school:add('Bradley', 5) |
42 |
| - school:add('Jeff', 1) |
43 |
| - local expected = { 'Bradley', 'Franklin' } |
44 |
| - local result = school:grade(5) |
45 |
| - assert.are.same(expected, result) |
| 67 | + assert.is_true(school:add('Blair', 2)) |
| 68 | + assert.is_true(school:add('James', 2)) |
| 69 | + assert.is_false(school:add('James', 3)) |
| 70 | + assert.is_true(school:add('Paul', 3)) |
| 71 | + end) |
| 72 | + |
| 73 | + it('student not added to multiple grades in the roster', function() |
| 74 | + local school = School:new() |
| 75 | + school:add('Blair', 2) |
| 76 | + school:add('James', 2) |
| 77 | + school:add('James', 3) |
| 78 | + school:add('Paul', 3) |
| 79 | + assert.are.same({ 'Blair', 'James', 'Paul' }, school:roster()) |
| 80 | + end) |
| 81 | + |
| 82 | + it('students are sorted by grades in the roster', function() |
| 83 | + local school = School:new() |
| 84 | + school:add('Jim', 3) |
| 85 | + school:add('Peter', 2) |
| 86 | + school:add('Anna', 1) |
| 87 | + assert.are.same({ 'Anna', 'Peter', 'Jim' }, school:roster()) |
46 | 88 | end)
|
47 | 89 |
|
48 |
| - it('grade returns an empty array if there are no students in that grade', function() |
| 90 | + it('students are sorted by name in the roster', function() |
49 | 91 | local school = School:new()
|
50 |
| - local result = school:grade(1) |
51 |
| - local expected = {} |
52 |
| - assert.are.same(expected, result) |
| 92 | + school:add('Peter', 2) |
| 93 | + school:add('Zoe', 2) |
| 94 | + school:add('Alex', 2) |
| 95 | + assert.are.same({ 'Alex', 'Peter', 'Zoe' }, school:roster()) |
53 | 96 | end)
|
54 | 97 |
|
55 |
| - it('the students names in each grade in the roster are sorted', function() |
| 98 | + it('students are sorted by grades and then by name in the roster', function() |
56 | 99 | local school = School:new()
|
57 |
| - school:add('Jennifer', 4) |
58 |
| - school:add('Kareem', 6) |
59 |
| - school:add('Christopher', 4) |
60 |
| - school:add('Kyle', 3) |
61 |
| - local expected = { [3] = { 'Kyle' }, [4] = { 'Christopher', 'Jennifer' }, [6] = { 'Kareem' } } |
62 |
| - local result = school:roster() |
63 |
| - assert.are.same(expected, result) |
| 100 | + school:add('Peter', 2) |
| 101 | + school:add('Anna', 1) |
| 102 | + school:add('Barb', 1) |
| 103 | + school:add('Zoe', 2) |
| 104 | + school:add('Alex', 2) |
| 105 | + school:add('Jim', 3) |
| 106 | + school:add('Charlie', 1) |
| 107 | + assert.are.same({ 'Anna', 'Barb', 'Charlie', 'Alex', 'Peter', 'Zoe', 'Jim' }, school:roster()) |
| 108 | + end) |
| 109 | + |
| 110 | + it('grade is empty if no students in the roster', function() |
| 111 | + local school = School:new() |
| 112 | + assert.are.same({}, school:grade(1)) |
| 113 | + end) |
| 114 | + |
| 115 | + it('grade is empty if no students in that grade', function() |
| 116 | + local school = School:new() |
| 117 | + school:add('Peter', 2) |
| 118 | + school:add('Zoe', 2) |
| 119 | + school:add('Alex', 2) |
| 120 | + school:add('Jim', 3) |
| 121 | + assert.are.same({}, school:grade(1)) |
| 122 | + end) |
| 123 | + |
| 124 | + it('student not added to same grade more than once', function() |
| 125 | + local school = School:new() |
| 126 | + school:add('Blair', 2) |
| 127 | + school:add('James', 2) |
| 128 | + school:add('James', 2) |
| 129 | + school:add('Paul', 2) |
| 130 | + assert.are.same({ 'Blair', 'James', 'Paul' }, school:grade(2)) |
| 131 | + end) |
| 132 | + |
| 133 | + it('student not added to multiple grades', function() |
| 134 | + local school = School:new() |
| 135 | + school:add('Blair', 2) |
| 136 | + school:add('James', 2) |
| 137 | + school:add('James', 3) |
| 138 | + school:add('Paul', 3) |
| 139 | + assert.are.same({ 'Blair', 'James' }, school:grade(2)) |
| 140 | + end) |
| 141 | + |
| 142 | + it('student not added to other grade for multiple grades', function() |
| 143 | + local school = School:new() |
| 144 | + school:add('Blair', 2) |
| 145 | + school:add('James', 2) |
| 146 | + school:add('James', 3) |
| 147 | + school:add('Paul', 3) |
| 148 | + assert.are.same({ 'Paul' }, school:grade(3)) |
| 149 | + end) |
| 150 | + |
| 151 | + it('students are sorted by name in a grade', function() |
| 152 | + local school = School:new() |
| 153 | + school:add('Franklin', 5) |
| 154 | + school:add('Bradley', 5) |
| 155 | + school:add('Jeff', 1) |
| 156 | + assert.are.same({ 'Bradley', 'Franklin' }, school:grade(5)) |
64 | 157 | end)
|
65 | 158 | end)
|
0 commit comments