Skip to content

Commit e37932c

Browse files
author
dyzheng
committed
fix: UT of input
1 parent 94e357f commit e37932c

1 file changed

Lines changed: 61 additions & 93 deletions

File tree

source/source_io/test_serial/read_input_item_test.cpp

Lines changed: 61 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,102 +1849,70 @@ TEST_F(InputTest, Item_test2)
18491849
}
18501850
}
18511851

1852-
TEST_F(InputParaTest, OutMatDH)
1852+
TEST_F(InputTest, Item_test_out_mat_vec)
18531853
{
1854-
std::string input_file = "./support/INPUT";
1855-
std::ofstream ofs(input_file);
1856-
ofs << "out_mat_dh 1" << std::endl;
1857-
ofs.close();
1858-
PARAM.input.Read(input_file);
1859-
EXPECT_EQ(PARAM.input.out_mat_dh[0], 1);
1860-
EXPECT_EQ(PARAM.input.out_mat_dh[1], 8);
1861-
remove(input_file.c_str());
1862-
1863-
ofs.open(input_file);
1864-
ofs << "out_mat_dh 1 12" << std::endl;
1865-
ofs.close();
1866-
PARAM.input.Read(input_file);
1867-
EXPECT_EQ(PARAM.input.out_mat_dh[0], 1);
1868-
EXPECT_EQ(PARAM.input.out_mat_dh[1], 12);
1869-
remove(input_file.c_str());
1870-
}
1854+
ModuleIO::ReadInput readinput(0);
1855+
readinput.check_ntype_flag = false;
1856+
Parameter param;
18711857

1872-
TEST_F(InputParaTest, OutMatDS)
1873-
{
1874-
std::string input_file = "./support/INPUT";
1875-
std::ofstream ofs(input_file);
1876-
ofs << "out_mat_ds 1" << std::endl;
1877-
ofs.close();
1878-
PARAM.input.Read(input_file);
1879-
EXPECT_EQ(PARAM.input.out_mat_ds[0], 1);
1880-
EXPECT_EQ(PARAM.input.out_mat_ds[1], 8);
1881-
remove(input_file.c_str());
1882-
1883-
ofs.open(input_file);
1884-
ofs << "out_mat_ds 1 10" << std::endl;
1885-
ofs.close();
1886-
PARAM.input.Read(input_file);
1887-
EXPECT_EQ(PARAM.input.out_mat_ds[0], 1);
1888-
EXPECT_EQ(PARAM.input.out_mat_ds[1], 10);
1889-
remove(input_file.c_str());
1890-
}
1858+
{ // out_mat_dh
1859+
auto it = find_label("out_mat_dh", readinput.input_lists);
1860+
it->second.str_values = {"1"};
1861+
it->second.read_value(it->second, param);
1862+
EXPECT_EQ(param.input.out_mat_dh[0], 1);
1863+
EXPECT_EQ(param.input.out_mat_dh[1], 8);
18911864

1892-
TEST_F(InputParaTest, OutMatT)
1893-
{
1894-
std::string input_file = "./support/INPUT";
1895-
std::ofstream ofs(input_file);
1896-
ofs << "out_mat_t 1" << std::endl;
1897-
ofs.close();
1898-
PARAM.input.Read(input_file);
1899-
EXPECT_EQ(PARAM.input.out_mat_t[0], 1);
1900-
EXPECT_EQ(PARAM.input.out_mat_t[1], 8);
1901-
remove(input_file.c_str());
1902-
1903-
ofs.open(input_file);
1904-
ofs << "out_mat_t 1 15" << std::endl;
1905-
ofs.close();
1906-
PARAM.input.Read(input_file);
1907-
EXPECT_EQ(PARAM.input.out_mat_t[0], 1);
1908-
EXPECT_EQ(PARAM.input.out_mat_t[1], 15);
1909-
remove(input_file.c_str());
1910-
}
1865+
it->second.str_values = {"1", "12"};
1866+
it->second.read_value(it->second, param);
1867+
EXPECT_EQ(param.input.out_mat_dh[0], 1);
1868+
EXPECT_EQ(param.input.out_mat_dh[1], 12);
1869+
}
1870+
{ // out_mat_ds
1871+
auto it = find_label("out_mat_ds", readinput.input_lists);
1872+
it->second.str_values = {"1"};
1873+
it->second.read_value(it->second, param);
1874+
EXPECT_EQ(param.input.out_mat_ds[0], 1);
1875+
EXPECT_EQ(param.input.out_mat_ds[1], 8);
19111876

1912-
TEST_F(InputParaTest, OutMatR)
1913-
{
1914-
std::string input_file = "./support/INPUT";
1915-
std::ofstream ofs(input_file);
1916-
ofs << "out_mat_r 1" << std::endl;
1917-
ofs.close();
1918-
PARAM.input.Read(input_file);
1919-
EXPECT_EQ(PARAM.input.out_mat_r[0], 1);
1920-
EXPECT_EQ(PARAM.input.out_mat_r[1], 8);
1921-
remove(input_file.c_str());
1922-
1923-
ofs.open(input_file);
1924-
ofs << "out_mat_r 1 6" << std::endl;
1925-
ofs.close();
1926-
PARAM.input.Read(input_file);
1927-
EXPECT_EQ(PARAM.input.out_mat_r[0], 1);
1928-
EXPECT_EQ(PARAM.input.out_mat_r[1], 6);
1929-
remove(input_file.c_str());
1930-
}
1877+
it->second.str_values = {"1", "10"};
1878+
it->second.read_value(it->second, param);
1879+
EXPECT_EQ(param.input.out_mat_ds[0], 1);
1880+
EXPECT_EQ(param.input.out_mat_ds[1], 10);
1881+
}
1882+
{ // out_mat_t
1883+
auto it = find_label("out_mat_t", readinput.input_lists);
1884+
it->second.str_values = {"1"};
1885+
it->second.read_value(it->second, param);
1886+
EXPECT_EQ(param.input.out_mat_t[0], 1);
1887+
EXPECT_EQ(param.input.out_mat_t[1], 8);
19311888

1932-
TEST_F(InputParaTest, OutMatXC2)
1933-
{
1934-
std::string input_file = "./support/INPUT";
1935-
std::ofstream ofs(input_file);
1936-
ofs << "out_mat_xc2 1" << std::endl;
1937-
ofs.close();
1938-
PARAM.input.Read(input_file);
1939-
EXPECT_EQ(PARAM.input.out_mat_xc2[0], 1);
1940-
EXPECT_EQ(PARAM.input.out_mat_xc2[1], 8);
1941-
remove(input_file.c_str());
1942-
1943-
ofs.open(input_file);
1944-
ofs << "out_mat_xc2 1 9" << std::endl;
1945-
ofs.close();
1946-
PARAM.input.Read(input_file);
1947-
EXPECT_EQ(PARAM.input.out_mat_xc2[0], 1);
1948-
EXPECT_EQ(PARAM.input.out_mat_xc2[1], 9);
1949-
remove(input_file.c_str());
1889+
it->second.str_values = {"1", "15"};
1890+
it->second.read_value(it->second, param);
1891+
EXPECT_EQ(param.input.out_mat_t[0], 1);
1892+
EXPECT_EQ(param.input.out_mat_t[1], 15);
1893+
}
1894+
{ // out_mat_r
1895+
auto it = find_label("out_mat_r", readinput.input_lists);
1896+
it->second.str_values = {"1"};
1897+
it->second.read_value(it->second, param);
1898+
EXPECT_EQ(param.input.out_mat_r[0], 1);
1899+
EXPECT_EQ(param.input.out_mat_r[1], 8);
1900+
1901+
it->second.str_values = {"1", "6"};
1902+
it->second.read_value(it->second, param);
1903+
EXPECT_EQ(param.input.out_mat_r[0], 1);
1904+
EXPECT_EQ(param.input.out_mat_r[1], 6);
1905+
}
1906+
{ // out_mat_xc2
1907+
auto it = find_label("out_mat_xc2", readinput.input_lists);
1908+
it->second.str_values = {"1"};
1909+
it->second.read_value(it->second, param);
1910+
EXPECT_EQ(param.input.out_mat_xc2[0], 1);
1911+
EXPECT_EQ(param.input.out_mat_xc2[1], 8);
1912+
1913+
it->second.str_values = {"1", "9"};
1914+
it->second.read_value(it->second, param);
1915+
EXPECT_EQ(param.input.out_mat_xc2[0], 1);
1916+
EXPECT_EQ(param.input.out_mat_xc2[1], 9);
1917+
}
19501918
}

0 commit comments

Comments
 (0)