add unit tests for sort() and rsort() special function

This commit is contained in:
Axel Kohlmeyer
2024-05-22 23:57:13 -04:00
parent 272ce64272
commit c95389d58c

View File

@ -337,6 +337,10 @@ TEST_F(VariableTest, Expressions)
command("variable vec1 vector \"[-2, 0, 1,2 ,3, 5 , 7\n]\""); command("variable vec1 vector \"[-2, 0, 1,2 ,3, 5 , 7\n]\"");
command("variable vec2 vector v_vec1*0.5"); command("variable vec2 vector v_vec1*0.5");
command("variable vec3 equal v_vec2[3]"); command("variable vec3 equal v_vec2[3]");
command("variable vec4 vector '[1, 5, 2.5, -10, -5, 20, 120, 4, 3, 3]'");
command("variable sort vector sort(v_vec4)");
command("variable rsrt vector rsort(v_vec4)");
command("variable isrt vector sort(v_one)");
variable->set("dummy index 1 2"); variable->set("dummy index 1 2");
END_HIDE_OUTPUT(); END_HIDE_OUTPUT();
@ -366,6 +370,8 @@ TEST_F(VariableTest, Expressions)
EXPECT_THAT(variable->retrieve("vec1"), StrEq("[-2,0,1,2,3,5,7]")); EXPECT_THAT(variable->retrieve("vec1"), StrEq("[-2,0,1,2,3,5,7]"));
EXPECT_THAT(variable->retrieve("vec2"), StrEq("[-1,0,0.5,1,1.5,2.5,3.5]")); EXPECT_THAT(variable->retrieve("vec2"), StrEq("[-1,0,0.5,1,1.5,2.5,3.5]"));
ASSERT_DOUBLE_EQ(variable->compute_equal("v_vec3"), 0.5); ASSERT_DOUBLE_EQ(variable->compute_equal("v_vec3"), 0.5);
EXPECT_THAT(variable->retrieve("sort"), StrEq("[-10,-5,1,2.5,3,3,4,5,20,120]"));
EXPECT_THAT(variable->retrieve("rsrt"), StrEq("[120,20,5,4,3,3,2.5,1,-5,-10]"));
TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*", TEST_FAILURE(".*ERROR: Variable six: Invalid thermo keyword 'XXX' in variable formula.*",
command("print \"${six}\"");); command("print \"${six}\""););
@ -377,6 +383,8 @@ TEST_F(VariableTest, Expressions)
command("print \"${err2}\"");); command("print \"${err2}\""););
TEST_FAILURE(".*ERROR on proc 0: Variable err3: Invalid power expression in variable formula.*", TEST_FAILURE(".*ERROR on proc 0: Variable err3: Invalid power expression in variable formula.*",
command("print \"${err3}\"");); command("print \"${err3}\""););
TEST_FAILURE(".*ERROR: Variable one: Mis-matched special function variable in variable formula.*",
command("print \"${isrt}\""););
} }
TEST_F(VariableTest, Functions) TEST_F(VariableTest, Functions)