1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-01-16 12:10:31 +00:00
conky/tests/test-algebra.cc

134 lines
4.8 KiB
C++
Raw Normal View History

2024-10-30 12:29:15 +00:00
#include "catch2/catch.hpp"
#include <algebra.h>
#include <config.h>
TEST_CASE("GetMatchTypeTest - ValidOperators") {
REQUIRE(get_match_type("a==b") == OP_EQ);
REQUIRE(get_match_type("a!=b") == OP_NEQ);
REQUIRE(get_match_type("a>b") == OP_GT);
REQUIRE(get_match_type("a>=b") == OP_GEQ);
REQUIRE(get_match_type("a<b") == OP_LT);
REQUIRE(get_match_type("a<=b") == OP_LEQ);
}
TEST_CASE("GetMatchTypeTest - InvalidOperators") {
REQUIRE(get_match_type("a=b") == -1);
REQUIRE(get_match_type("a!b") == -1);
REQUIRE(get_match_type("a=b") == -1);
}
TEST_CASE("GetMatchTypeTest - NoOperators") {
REQUIRE(get_match_type("abc") == -1);
REQUIRE(get_match_type("123") == -1);
REQUIRE(get_match_type("") == -1);
}
TEST_CASE("find_match_op identifies operators correctly", "[find_match_op]") {
SECTION("Single character operators") {
REQUIRE(find_match_op("a < b") == 2);
REQUIRE(find_match_op("a > b") == 2);
}
SECTION("Double character operators") {
REQUIRE(find_match_op("a == b") == 2);
REQUIRE(find_match_op("a != b") == 2);
REQUIRE(find_match_op("a >= b") == 2);
REQUIRE(find_match_op("a <= b") == 2);
}
SECTION("No operator present") { REQUIRE(find_match_op("a b") == -1); }
SECTION("Invalid operators") {
REQUIRE(find_match_op("a = b") == -1);
REQUIRE(find_match_op("a ! b") == -1);
}
SECTION("Operators at different positions") {
REQUIRE(find_match_op("x == y") == 2);
REQUIRE(find_match_op("x != y") == 2);
REQUIRE(find_match_op("x >= y") == 2);
REQUIRE(find_match_op("x <= y") == 2);
REQUIRE(find_match_op("x < y") == 2);
REQUIRE(find_match_op("x > y") == 2);
}
SECTION("Empty string") { REQUIRE(find_match_op("") == -1); }
}
TEST_CASE("GetMatchTypeTest - More test cases") {
2024-10-30 12:53:09 +00:00
REQUIRE(get_match_type("\"a!b\" == \"ab\"") == OP_EQ); // "a!b" == "ab"
REQUIRE(get_match_type("\"a!/b\" == \"a!/b\"") == OP_EQ); // "a!/b" == "a!/b"
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"a!=/a==b\" == \"a!=/a==b\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // "a!=/a==b" == "a!=/a==b"
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"a!=/b==b\" == \"a!==/a==b\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // "a!=/b==b" == "a!==/a==b"
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"a!======b\" == \"!==/==\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // "a!======b" == "!==/=="
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\" !=<>==\" == \" !=<>==\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // " !=<>==" == " !=<>=="
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"a!=><==\" < \"b!=><==\"") ==
2024-10-30 12:53:09 +00:00
OP_LT); // "a!=><==" < "b!=><=="
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"!=<>==\" == \"!=<>==\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // "!=<>==" == "!=<>=="
REQUIRE(get_match_type("\"=\" == \"=\"") == OP_EQ); // "=" == "="
2024-10-30 12:29:15 +00:00
REQUIRE(get_match_type("\"FRITZ!Box 7520 HI\" == \"off/any\"") ==
2024-10-30 12:53:09 +00:00
OP_EQ); // "FRITZ!Box 7520 HI" == "off/any"
2024-10-30 12:29:15 +00:00
}
TEST_CASE("CompareTest - ValidOperators") {
REQUIRE(compare("\"a\"==\"b\"") == 0);
REQUIRE(compare("\"a\"!=\"b\"") == 1);
REQUIRE(compare("\"a\">\"b\"") == 0);
REQUIRE(compare("\"a\">=\"b\"") == 0);
REQUIRE(compare("\"a\"<\"b\"") == 1);
REQUIRE(compare("\"a\"<=\"b\"") == 1);
}
TEST_CASE("CompareTest - ValidOperators with Integers") {
REQUIRE(compare("1==1") == 1);
REQUIRE(compare("1!=2") == 1);
REQUIRE(compare("2>1") == 1);
REQUIRE(compare("2>=1") == 1);
REQUIRE(compare("1<2") == 1);
REQUIRE(compare("1<=2") == 1);
}
TEST_CASE("CompareTest - ValidOperators with Doubles") {
REQUIRE(compare("1.0==1.0") == 1);
REQUIRE(compare("1.0!=2.0") == 1);
REQUIRE(compare("2.0>1.0") == 1);
REQUIRE(compare("2.0>=1.0") == 1);
REQUIRE(compare("1.0<2.0") == 1);
REQUIRE(compare("1.0<=2.0") == 1);
}
TEST_CASE("CompareTest - InvalidOperators") {
REQUIRE(compare("\"a\"=\"b\"") == -2);
REQUIRE(compare("\"a\"!\"b\"") == -2);
REQUIRE(compare("\"a\"=\"b\"") == -2);
}
TEST_CASE("CompareTest - NoOperators") {
REQUIRE(compare("abc") == -2);
REQUIRE(compare("123") == -2);
REQUIRE(compare("") == -2);
}
TEST_CASE("CompareTest - More test cases") {
2024-10-30 12:53:09 +00:00
REQUIRE(compare("\"a!b\" == \"ab\"") == 0); // "a!b" == "ab"
REQUIRE(compare("\"a!/b\" == \"a!/b\"") == 1); // "a!/b" == "a!/b"
2024-10-30 12:29:15 +00:00
REQUIRE(compare("\"a!=/a==b\" == \"a!=/a==b\"") ==
2024-10-30 12:53:09 +00:00
1); // "a!=/a==b" == "a!=/a==b"
2024-10-30 12:29:15 +00:00
REQUIRE(compare("\"a!=/b==b\" == \"a!==/a==b\"") ==
2024-10-30 12:53:09 +00:00
0); // "a!=/b==b" == "a!==/a==b"
2024-10-30 12:29:15 +00:00
REQUIRE(compare("\"a!======b\" == \"!==/==\"") ==
2024-10-30 12:53:09 +00:00
0); // "a!======b" == "!==/=="
2024-10-30 12:29:15 +00:00
REQUIRE(compare("\" !=<>==\" == \" !=<>==\"") ==
2024-10-30 12:53:09 +00:00
1); // " !=<>==" == " !=<>=="
REQUIRE(compare("\"a!=><==\" < \"b!=><==\"") == 1); // "a!=><==" < "b!=><=="
REQUIRE(compare("\"!=<>==\" == \"!=<>==\"") == 1); // "!=<>==" == "!=<>=="
REQUIRE(compare("\"=\" == \"=\"") == 1); // "=" == "="
2024-10-30 12:29:15 +00:00
REQUIRE(compare("\"FRITZ!Box 7520 HI\" == \"off/any\"") ==
2024-10-30 12:53:09 +00:00
0); // "FRITZ!Box 7520 HI" == "off/any"
2024-10-30 12:29:15 +00:00
}