|
| 1 | +;;; grade-school-test.el --- Grade School (exercism) -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;;; Commentary: |
| 4 | + |
| 5 | +;;; Code: |
| 6 | + |
| 7 | + |
| 8 | +(load-file "grade-school.el") |
| 9 | +(declare-function roster "grade-school.el" (students)) |
| 10 | +(declare-function add "grade-school.el" (students)) |
| 11 | +(declare-function grade "grade-school.el" (desired-grade students)) |
| 12 | + |
| 13 | + |
| 14 | +(ert-deftest roster-is-empty-when-no-student-is-added () |
| 15 | + (let ((test-school (make-school))) |
| 16 | + (should (equal (roster test-school) '())))) |
| 17 | + |
| 18 | + |
| 19 | +(ert-deftest add-a-student () |
| 20 | + (let ((test-school (make-school))) |
| 21 | + (should (add test-school "Aimee" 2)))) |
| 22 | + |
| 23 | + |
| 24 | +(ert-deftest student-is-added-to-the-roster () |
| 25 | + (let ((test-school (make-school))) |
| 26 | + (add test-school "Aimee" 2) |
| 27 | + (should (equal (roster test-school) '("Aimee"))))) |
| 28 | + |
| 29 | + |
| 30 | +(ert-deftest adding-multiple-students-in-the-same-grade-in-the-roster () |
| 31 | + (let ((test-school (make-school))) |
| 32 | + (should (add test-school "Blair" 2)) |
| 33 | + (should (add test-school "James" 2)) |
| 34 | + (should (add test-school "Paul" 2)))) |
| 35 | + |
| 36 | + |
| 37 | +(ert-deftest multiple-students-in-the-same-grade-are-added-to-the-roster () |
| 38 | + (let ((test-school (make-school))) |
| 39 | + (add test-school "Blair" 2) |
| 40 | + (add test-school "James" 2) |
| 41 | + (add test-school "Paul" 2) |
| 42 | + (should (equal (roster test-school) '("Blair" "James" "Paul"))))) |
| 43 | + |
| 44 | + |
| 45 | +(ert-deftest cannot-add-student-to-same-grade-in-the-roster-more-than-once () |
| 46 | + (let ((test-school (make-school))) |
| 47 | + (should (add test-school "Blair" 2)) |
| 48 | + (should (add test-school "James" 2)) |
| 49 | + (should-not (add test-school "James" 2)) |
| 50 | + (should (add test-school "Paul" 2)))) |
| 51 | + |
| 52 | + |
| 53 | +(ert-deftest student-not-added-to-same-grade-in-the-roster-more-than-once () |
| 54 | + (let ((test-school (make-school))) |
| 55 | + (add test-school "Blair" 2) |
| 56 | + (add test-school "James" 2) |
| 57 | + (add test-school "James" 2) |
| 58 | + (add test-school "Paul" 2) |
| 59 | + (should (equal (roster test-school) '("Blair" "James" "Paul"))))) |
| 60 | + |
| 61 | + |
| 62 | +(ert-deftest adding-students-in-multiple-grades () |
| 63 | + (let ((test-school (make-school))) |
| 64 | + (should (add test-school "Chelsea" 3)) |
| 65 | + (should (add test-school "Loagan" 7)))) |
| 66 | + |
| 67 | + |
| 68 | +(ert-deftest students-in-multiple-grades-are-added-to-the-roster () |
| 69 | + (let ((test-school (make-school))) |
| 70 | + (add test-school "Chelsea" 3) |
| 71 | + (add test-school "Logan" 7) |
| 72 | + (should (equal (roster test-school) '("Chelsea" "Logan"))))) |
| 73 | + |
| 74 | + |
| 75 | +(ert-deftest cannot-add-same-student-to-multiple-grades-in-the-roster () |
| 76 | + (let ((test-school (make-school))) |
| 77 | + (should (add test-school "Blair" 2)) |
| 78 | + (should (add test-school "James" 2)) |
| 79 | + (should-not (add test-school "James" 3)) |
| 80 | + (should (add test-school "Paul" 3)))) |
| 81 | + |
| 82 | + |
| 83 | +(ert-deftest student-not-added-to-multiple-grades-in-the-roster () |
| 84 | + (let ((test-school (make-school))) |
| 85 | + (add test-school "Blair" 2) |
| 86 | + (add test-school "James" 2) |
| 87 | + (add test-school "James" 3) |
| 88 | + (add test-school "Paul" 3) |
| 89 | + (should (equal (roster test-school) '("Blair" "James" "Paul"))))) |
| 90 | + |
| 91 | + |
| 92 | +(ert-deftest students-are-sorted-by-grades-in-the-roster () |
| 93 | + (let ((test-school (make-school))) |
| 94 | + (add test-school "Jim" 3) |
| 95 | + (add test-school "Peter" 2) |
| 96 | + (add test-school "Anna" 1) |
| 97 | + (should (equal (roster test-school) '("Anna" "Peter" "Jim"))))) |
| 98 | + |
| 99 | + |
| 100 | +(ert-deftest students-are-sorted-by-name-in-the-roster () |
| 101 | + (let ((test-school (make-school))) |
| 102 | + (add test-school "Peter" 2) |
| 103 | + (add test-school "Zoe" 2) |
| 104 | + (add test-school "Alex" 2) |
| 105 | + (should (equal (roster test-school) '("Alex" "Peter" "Zoe"))))) |
| 106 | + |
| 107 | + |
| 108 | +(ert-deftest students-are-sorted-by-grades-and-then-by-name-in-the-roster () |
| 109 | + (let ((test-school (make-school))) |
| 110 | + (add test-school "Peter" 2) |
| 111 | + (add test-school "Anna" 1) |
| 112 | + (add test-school "Barb" 1) |
| 113 | + (add test-school "Zoe" 2) |
| 114 | + (add test-school "Alex" 2) |
| 115 | + (add test-school "Jim" 3) |
| 116 | + (add test-school "Charlie" 1) |
| 117 | + (should (equal (roster test-school) '("Anna" "Barb" "Charlie" "Alex" "Peter" "Zoe" "Jim"))))) |
| 118 | + |
| 119 | + |
| 120 | +(ert-deftest grade-is-empty-if-no-students-in-the-roster () |
| 121 | + (let ((test-school (make-school))) |
| 122 | + (should (equal (grade test-school 1) '())))) |
| 123 | + |
| 124 | + |
| 125 | +(ert-deftest grade-is-empty-if-no-students-in-that-grade () |
| 126 | + (let ((test-school (make-school))) |
| 127 | + (add test-school "Peter" 2) |
| 128 | + (add test-school "Zoe" 2) |
| 129 | + (add test-school "Alex" 2) |
| 130 | + (add test-school "Jim" 3) |
| 131 | + (should (equal (grade test-school 1) '())))) |
| 132 | + |
| 133 | + |
| 134 | +(ert-deftest student-not-added-to-same-grade-more-than-once () |
| 135 | + (let ((test-school (make-school))) |
| 136 | + (add test-school "Blair" 2) |
| 137 | + (add test-school "James" 2) |
| 138 | + (add test-school "James" 2) |
| 139 | + (add test-school "Paul" 2) |
| 140 | + (should (equal (grade test-school 2) '("Blair" "James" "Paul"))))) |
| 141 | + |
| 142 | + |
| 143 | +(ert-deftest student-not-added-to-multiple-grades () |
| 144 | + (let ((test-school (make-school))) |
| 145 | + (add test-school "Blair" 2) |
| 146 | + (add test-school "James" 2) |
| 147 | + (add test-school "James" 3) |
| 148 | + (add test-school "Paul" 3) |
| 149 | + (should (equal (grade test-school 2) '("Blair" "James"))))) |
| 150 | + |
| 151 | + |
| 152 | +(ert-deftest student-not-added-to-other-grade-for-multiple-grades () |
| 153 | + (let ((test-school (make-school))) |
| 154 | + (add test-school "Blair" 2) |
| 155 | + (add test-school "James" 2) |
| 156 | + (add test-school "James" 3) |
| 157 | + (add test-school "Paul" 3) |
| 158 | + (should (equal (grade test-school 3) '("Paul"))))) |
| 159 | + |
| 160 | + |
| 161 | +(ert-deftest students-are-sorted-by-name-in-a-grade () |
| 162 | + (let ((test-school (make-school))) |
| 163 | + (add test-school "Franklin" 5) |
| 164 | + (add test-school "Bradley" 5) |
| 165 | + (add test-school "Jeff" 1) |
| 166 | + (should (equal (grade test-school 5) '("Bradley" "Franklin"))))) |
| 167 | + |
| 168 | + |
| 169 | +(provide 'grade-school-test) |
| 170 | +;;; grade-school-test.el ends here |
0 commit comments