#include "making_the_grade.cpp" #ifdef EXERCISM_TEST_SUITE #include #else #include "test/catch.hpp" #endif using namespace std; TEST_CASE("Check correct mark conversion (empty)", "[task_1]") { vector input{}; vector expected{}; vector actual = round_down_scores(input); REQUIRE(expected == actual); } TEST_CASE("Check correct mark conversion (all < 0.5)", "[task_1]") { vector input{5.2, 77.1, 91.0}; vector expected{5, 77, 91}; vector actual = round_down_scores(input); REQUIRE(expected == actual); } TEST_CASE("Check correct mark conversion (all mixed)", "[task_1]") { vector input{5.2, 77.1, 91.0, 42.9, 11.6544}; vector expected{5, 77, 91, 42, 11}; vector actual = round_down_scores(input); REQUIRE(expected == actual); } TEST_CASE("Count failed students (none failed)", "[task_2]") { vector input{89, 85, 42, 57, 90, 100, 95, 48, 70, 96}; int expected{0}; int actual = count_failed_students(input); REQUIRE(expected == actual); } TEST_CASE("Count failed students (some failed)", "[task_2]") { vector input{40, 40, 35, 70, 30, 41, 90}; int expected{4}; int actual = count_failed_students(input); REQUIRE(expected == actual); } TEST_CASE("Test threshold (empty)", "[task_3]") { vector input{}; int threshold{98}; vector expected{}; vector actual = above_threshold(input, threshold); REQUIRE(expected == actual); } TEST_CASE("Test threshold (some above threshold)", "[task_3]") { vector input{88, 29, 91, 64, 78, 43, 41, 77, 36, 50}; int threshold{80}; vector expected{88, 91}; vector actual = above_threshold(input, threshold); REQUIRE(expected == actual); } TEST_CASE("Test threshold (none above threshold)", "[task_3]") { vector input{88, 29, 91, 64, 78, 43, 41, 77, 36, 50}; int threshold{99}; vector expected{}; vector actual = above_threshold(input, threshold); REQUIRE(expected == actual); } TEST_CASE("Test threshold (some on threshold)", "[task_3]") { vector input{88, 29, 91, 64, 78, 43, 41, 77, 80, 80}; int threshold{80}; vector expected{88, 91, 80, 80}; vector actual = above_threshold(input, threshold); REQUIRE(expected == actual); } TEST_CASE("Test letter grades: 100", "[task_4]") { int input{100}; array expected{41, 56, 71, 86}; array actual = letter_grades(input); REQUIRE(expected == actual); } TEST_CASE("Test letter grades: 97", "[task_4]") { int input{97}; array expected{41, 55, 69, 83}; array actual = letter_grades(input); REQUIRE(expected == actual); } TEST_CASE("Test letter grades: 81", "[task_4]") { int input{81}; array expected{41, 51, 61, 71}; array actual = letter_grades(input); REQUIRE(expected == actual); } TEST_CASE("Rank one student", "[task_5]") { vector grades{82}; vector names{"Betty"}; vector expected{"1. Betty: 82"}; vector actual = student_ranking(grades, names); REQUIRE(expected == actual); } TEST_CASE("Rank several student", "[task_5]") { vector grades{100, 98, 92, 86, 70, 68, 67, 60}; vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; vector expected{"1. Rui: 100", "2. Betty: 98", "3. Joci: 92", "4. Yoshi: 86", "5. Kora: 70", "6. Bern: 68", "7. Jan: 67", "8. Rose: 60"}; vector actual = student_ranking(grades, names); REQUIRE(expected == actual); } TEST_CASE("No perfect score", "[task_6]") { vector grades{11, 34, 92, 23, 70, 76, 67, 60}; vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; string expected{""}; string actual = perfect_score(grades, names); REQUIRE(expected == actual); } TEST_CASE("One perfect score", "[task_6]") { vector grades{11, 34, 92, 23, 70, 76, 67, 100}; vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; string expected{"Rose"}; string actual = perfect_score(grades, names); REQUIRE(expected == actual); } TEST_CASE("Several perfect scores", "[task_6]") { vector grades{11, 100, 92, 23, 70, 100, 67, 100}; vector names{"Rui", "Betty", "Joci", "Yoshi", "Kora", "Bern", "Jan", "Rose"}; string expected{"Betty"}; string actual = perfect_score(grades, names); REQUIRE(expected == actual); } #if defined(EXERCISM_RUN_ALL_TESTS) #endif