From f4f5820e1e80d384e90c8c3c1e3b41951cd9d518 Mon Sep 17 00:00:00 2001 From: Matthias Rahlf Date: Sun, 2 Jun 2019 11:05:05 +0200 Subject: [PATCH 1/2] grade-school: Force const on roster() and grade() Currently school::roster() and school::grade() can be implemented as non-const methods. Logically it makes sense to be able to call those two methods on a const instance because they should not modify that instance. --- exercises/grade-school/grade_school_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/grade-school/grade_school_test.cpp b/exercises/grade-school/grade_school_test.cpp index 2478bff5..8a197e60 100644 --- a/exercises/grade-school/grade_school_test.cpp +++ b/exercises/grade-school/grade_school_test.cpp @@ -6,7 +6,7 @@ using namespace std; TEST_CASE("a_new_school_has_an_empty_roster") { - grade_school::school school_; + const grade_school::school school_; REQUIRE(school_.roster().empty()); } @@ -62,7 +62,7 @@ TEST_CASE("grade_returns_the_students_in_that_grade_in_alphabetical_order") TEST_CASE("grade_returns_an_empty_array_if_there_are_no_students_in_that_grade") { - grade_school::school school_; + const grade_school::school school_; const auto actual = school_.grade(1); REQUIRE(actual.empty()); @@ -88,7 +88,7 @@ TEST_CASE("the_student_names_in_each_grade_in_the_roster_are_sorted") TEST_CASE("checking_a_grade_should_not_change_the_roster") { - grade_school::school school_; + const grade_school::school school_; school_.grade(1); REQUIRE(school_.roster().empty()); } From 7349a4078ee9541ff13ede498ea9757ee7aac908 Mon Sep 17 00:00:00 2001 From: Patrick Jackson Date: Sat, 14 Sep 2019 08:27:02 -0700 Subject: [PATCH 2/2] Adding value initialization. --- exercises/grade-school/grade_school_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/grade-school/grade_school_test.cpp b/exercises/grade-school/grade_school_test.cpp index 8a197e60..15d4d0bb 100644 --- a/exercises/grade-school/grade_school_test.cpp +++ b/exercises/grade-school/grade_school_test.cpp @@ -6,7 +6,7 @@ using namespace std; TEST_CASE("a_new_school_has_an_empty_roster") { - const grade_school::school school_; + const grade_school::school school_{}; REQUIRE(school_.roster().empty()); } @@ -62,7 +62,7 @@ TEST_CASE("grade_returns_the_students_in_that_grade_in_alphabetical_order") TEST_CASE("grade_returns_an_empty_array_if_there_are_no_students_in_that_grade") { - const grade_school::school school_; + const grade_school::school school_{}; const auto actual = school_.grade(1); REQUIRE(actual.empty()); @@ -88,7 +88,7 @@ TEST_CASE("the_student_names_in_each_grade_in_the_roster_are_sorted") TEST_CASE("checking_a_grade_should_not_change_the_roster") { - const grade_school::school school_; + const grade_school::school school_{}; school_.grade(1); REQUIRE(school_.roster().empty()); }