Skip to content

Commit 740a588

Browse files
author
David Chu
committed
test: fix get_vector_with_default
Test case 3 only has 2 elements. The comparison design requires all test cases to have the same length as the first case.
1 parent 61f6818 commit 740a588

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

test/fixtures/config.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ not_int_arr = a b c d e
88
[section2]
99

1010
any_vec = 1 2 3
11-
doubles = 1.23 4.56
11+
doubles = 1.23 4.56

test/tests.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ TEST(INIReader, get_vector) {
2525
const std::vector<int> ans1{1, 2, 3};
2626
const std::vector<std::string> ans2{"1", "2", "3"};
2727

28-
const auto& vec1 = r.GetVector<int>("section2", "any_vec");
29-
const auto& vec2 = r.GetVector<>("section2", "any_vec");
30-
31-
for (int i = 0; i < ans1.size(); ++i) {
32-
EXPECT_EQ(vec1[i], ans1[i]);
33-
EXPECT_EQ(vec2[i], ans2[i]);
34-
}
28+
ASSERT_EQ(r.GetVector<int>("section2", "any_vec"), ans1);
29+
ASSERT_EQ(r.GetVector<>("section2", "any_vec"), ans2);
3530
}
3631

3732
TEST(INIReader, get_single_value_with_default) {
@@ -58,18 +53,16 @@ TEST(INIReader, get_vector_with_default) {
5853
const auto& vec1 = r.GetVector<int>("section2", "not_exist", ans1);
5954
const auto& vec2 = r.GetVector<std::string>("section2", "not_exist", std::vector<std::string>{"1", "2", "3"});
6055
const auto& vec3 = r.GetVector<double>("section2", "doubles", std::vector<double>{0});
61-
62-
for (int i = 0; i < ans1.size(); ++i) {
63-
EXPECT_EQ(vec1[i], ans1[i]);
64-
EXPECT_EQ(vec2[i], ans2[i]);
65-
EXPECT_EQ(vec3[i], ans3[i]);
66-
}
56+
57+
ASSERT_EQ(vec1, ans1);
58+
ASSERT_EQ(vec2, ans2);
59+
ASSERT_EQ(vec3, ans3);
6760
}
6861

6962

7063
TEST(INIReader, exception) {
7164

72-
65+
7366
EXPECT_THROW(INIReader{"QQ"}, std::runtime_error); // file not found
7467
EXPECT_THROW(INIReader{"./fixtures/bad_file.ini"}, std::runtime_error); // parse error
7568

@@ -82,15 +75,15 @@ TEST(INIReader, exception) {
8275
// parse error
8376
EXPECT_THROW(r.Get<int>("section1", "not_int"), std::runtime_error);
8477
EXPECT_THROW(r.GetVector<int>("section1", "not_int_arr"), std::runtime_error);
85-
78+
8679
}
8780

8881

8982
TEST(INIReader, read_big_file) {
9083
INIReader r{"./fixtures/bigfile.ini"};
91-
84+
9285
for (int i = 1; i <= 1000; ++i) {
9386
const auto& v = r.Get<int>("section", "key" + std::to_string(i));
9487
EXPECT_EQ(v, i);
9588
}
96-
}
89+
}

0 commit comments

Comments
 (0)