From 51d4a685147a2426b9458e5f800d7fa0ecd4ec04 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Thu, 27 Jul 2023 16:24:28 +0200 Subject: [PATCH] tests: improve test suite --- qschematic/wire_system/test/tests/line.cpp | 26 ++--- qschematic/wire_system/test/tests/manager.cpp | 66 ++++++------- qschematic/wire_system/test/tests/nets.cpp | 14 +-- qschematic/wire_system/test/tests/wire.cpp | 98 +++++++++---------- 4 files changed, 102 insertions(+), 102 deletions(-) diff --git a/qschematic/wire_system/test/tests/line.cpp b/qschematic/wire_system/test/tests/line.cpp index 9b704af..6e0d62b 100644 --- a/qschematic/wire_system/test/tests/line.cpp +++ b/qschematic/wire_system/test/tests/line.cpp @@ -7,47 +7,47 @@ TEST_SUITE("Line") { wire_system::line line(QPointF(10, 20), QPointF(10, 20)); - REQUIRE(line.is_null()); - REQUIRE(line.is_horizontal()); - REQUIRE(line.is_vertical()); + CHECK(line.is_null()); + CHECK(line.is_horizontal()); + CHECK(line.is_vertical()); } TEST_CASE("is_horizontal()") { wire_system::line line(QPointF(10, 20), QPointF(-12.5, 20)); - REQUIRE_FALSE(line.is_null()); - REQUIRE(line.is_horizontal()); - REQUIRE_FALSE(line.is_vertical()); + CHECK_FALSE(line.is_null()); + CHECK(line.is_horizontal()); + CHECK_FALSE(line.is_vertical()); } TEST_CASE("is_vertical()") { wire_system::line line(QPointF(10, 20), QPointF(10, 1000)); - REQUIRE_FALSE(line.is_null()); - REQUIRE(line.is_vertical()); - REQUIRE_FALSE(line.is_horizontal()); + CHECK_FALSE(line.is_null()); + CHECK(line.is_vertical()); + CHECK_FALSE(line.is_horizontal()); } - TEST_CASE("lenght()") + TEST_CASE("length()") { SUBCASE("line 1") { wire_system::line line(QPointF(0, 0), QPointF(0, 10)); - REQUIRE(line.lenght() == 10); + CHECK_EQ(line.lenght(), doctest::Approx(10)); } SUBCASE("line 2") { wire_system::line line(QPointF(0, 0), QPointF(0, -10)); - REQUIRE(line.lenght() == 10); + CHECK_EQ(line.lenght(), doctest::Approx(10)); } SUBCASE("line 3") { wire_system::line line(QPointF(12.534, -123.643), QPointF(62.3, 15.535)); - REQUIRE(doctest::Approx(line.lenght()).epsilon(0.01) == 147.8); + CHECK_EQ(line.lenght(), doctest::Approx(147.8).epsilon(0.01)); } } } \ No newline at end of file diff --git a/qschematic/wire_system/test/tests/manager.cpp b/qschematic/wire_system/test/tests/manager.cpp index bcae986..269d574 100644 --- a/qschematic/wire_system/test/tests/manager.cpp +++ b/qschematic/wire_system/test/tests/manager.cpp @@ -13,11 +13,11 @@ TEST_SUITE("Manager") wire1->append_point({0, 0}); wire1->append_point({10, 0}); - REQUIRE(wire1->points_count() == 2); + REQUIRE_EQ(wire1->points_count(), 2); manager.add_wire(wire1); - REQUIRE(manager.wires().count() == 1); + REQUIRE_EQ(manager.wires().count(), 1); REQUIRE(wire1->net().get()); auto wire2 = std::make_shared(); @@ -25,11 +25,11 @@ TEST_SUITE("Manager") wire2->append_point({10, 20}); wire2->append_point({20, 20}); - REQUIRE(wire2->points_count() == 3); + REQUIRE_EQ(wire2->points_count(), 3); manager.add_wire(wire2); - REQUIRE(manager.wires().count() == 2); + REQUIRE_EQ(manager.wires().count(), 2); REQUIRE(wire2->net().get()); } @@ -53,9 +53,9 @@ TEST_SUITE("Manager") manager.generate_junctions(); // Make sure the wires are connected - REQUIRE(manager.wires_connected_to(wire1).count() == 2); + REQUIRE_EQ(manager.wires_connected_to(wire1).count(), 2); REQUIRE(wire1->net().get()); - REQUIRE(wire1->net().get() == wire2->net().get()); + REQUIRE_EQ(wire1->net().get(), wire2->net().get()); } TEST_CASE ("connect_wire(): Wire can be connected manually") @@ -81,7 +81,7 @@ TEST_SUITE("Manager") manager.connect_wire(wire1.get(), wire2.get(), 1); // Make sure the wires are connected - REQUIRE(manager.wires_connected_to(wire1).count() == 2); + REQUIRE_EQ(manager.wires_connected_to(wire1).count(), 2); REQUIRE(wire1->net().get()); REQUIRE_EQ(wire1->net().get(), wire2->net().get()); REQUIRE(wire2->points().last().is_junction()); @@ -137,9 +137,9 @@ TEST_SUITE("Manager") manager.attach_wire_to_connector(wire.get(), &conn); // Make sure the wire has been attached - REQUIRE(manager.attached_wire(&conn) == wire.get()); - REQUIRE(manager.point_is_attached(wire.get(), 0) == false); - REQUIRE(manager.point_is_attached(wire.get(), 1) == true); + REQUIRE_EQ(manager.attached_wire(&conn), wire.get()); + REQUIRE_EQ(manager.point_is_attached(wire.get(), 0), false); + REQUIRE_EQ(manager.point_is_attached(wire.get(), 1), true); } SUBCASE("The wires is not on the connector") { @@ -148,9 +148,9 @@ TEST_SUITE("Manager") manager.attach_wire_to_connector(wire.get(), &conn); // Make sure the wire has not been attached - REQUIRE(manager.attached_wire(&conn) == nullptr); - REQUIRE(manager.point_is_attached(wire.get(), 0) == false); - REQUIRE(manager.point_is_attached(wire.get(), 1) == false); + REQUIRE_EQ(manager.attached_wire(&conn), nullptr); + REQUIRE_EQ(manager.point_is_attached(wire.get(), 0), false); + REQUIRE_EQ(manager.point_is_attached(wire.get(), 1), false); } } @@ -183,11 +183,11 @@ TEST_SUITE("Manager") manager.connector_moved(&conn); // Make sure every thing is as expected - REQUIRE(wire->points_count() == 4); - REQUIRE(wire->points().at(0).toPointF() == QPointF(0, 10)); - REQUIRE(wire->points().at(1).toPointF() == QPointF(5, 10)); - REQUIRE(wire->points().at(2).toPointF() == QPointF(5, 20)); - REQUIRE(wire->points().at(3).toPointF() == QPointF(10, 20)); + REQUIRE_EQ(wire->points_count(), 4); + REQUIRE_EQ(wire->points().at(0).toPointF(), QPointF(0, 10)); + REQUIRE_EQ(wire->points().at(1).toPointF(), QPointF(5, 10)); + REQUIRE_EQ(wire->points().at(2).toPointF(), QPointF(5, 20)); + REQUIRE_EQ(wire->points().at(3).toPointF(), QPointF(10, 20)); } SUBCASE("Straight angles are not maintained") { @@ -200,9 +200,9 @@ TEST_SUITE("Manager") manager.connector_moved(&conn); // Make sure everything is as expected - REQUIRE(wire->points_count() == 2); - REQUIRE(wire->points().at(0).toPointF() == QPointF(0, 10)); - REQUIRE(wire->points().at(1).toPointF() == QPointF(10, 20)); + REQUIRE_EQ(wire->points_count(), 2); + REQUIRE_EQ(wire->points().at(0).toPointF(), QPointF(0, 10)); + REQUIRE_EQ(wire->points().at(1).toPointF(), QPointF(10, 20)); } } @@ -229,42 +229,42 @@ TEST_SUITE("Manager") manager.attach_wire_to_connector(wire.get(), &conn2); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 1); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 1); // Insert a point between the two points wire->insert_point(1, QPointF(40, 40)); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 2); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 2); // Prepend a point wire->prepend_point(QPointF(0, 20)); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 3); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 3); // Append a point wire->append_point(QPointF(80, 20)); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 4); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 4); // Simplify the wire wire->simplify(); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 2); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 2); // Remove the middle point wire->remove_point(1); // Make sure the correct points are attached to the connectors - REQUIRE(manager.attached_point(&conn1) == 0); - REQUIRE(manager.attached_point(&conn2) == 1); + REQUIRE_EQ(manager.attached_point(&conn1), 0); + REQUIRE_EQ(manager.attached_point(&conn2), 1); } } diff --git a/qschematic/wire_system/test/tests/nets.cpp b/qschematic/wire_system/test/tests/nets.cpp index 34bdb4e..5e66c58 100644 --- a/qschematic/wire_system/test/tests/nets.cpp +++ b/qschematic/wire_system/test/tests/nets.cpp @@ -11,7 +11,7 @@ TEST_SUITE("Net") net->set_name(QString("test net")); - REQUIRE(net->name() == "test net"); + CHECK_EQ(net->name(), "test net"); } TEST_CASE("Wires can be added and removed") @@ -27,17 +27,17 @@ TEST_SUITE("Net") net->addWire(wire2); // Make sure the wires are in the net - REQUIRE(net->wires().count() == 2); - REQUIRE(net->contains(wire1)); - REQUIRE(net->contains(wire2)); + CHECK_EQ(net->wires().count(), 2); + CHECK(net->contains(wire1)); + CHECK(net->contains(wire2)); // Remove the wires net->removeWire(wire1); net->removeWire(wire2); // Make sure the wires are not in the net - REQUIRE(net->wires().count() == 0); - REQUIRE_FALSE(net->contains(wire1)); - REQUIRE_FALSE(net->contains(wire2)); + CHECK_EQ(net->wires().count(), 0); + CHECK_FALSE(net->contains(wire1)); + CHECK_FALSE(net->contains(wire2)); } } diff --git a/qschematic/wire_system/test/tests/wire.cpp b/qschematic/wire_system/test/tests/wire.cpp index c06509c..0aca482 100644 --- a/qschematic/wire_system/test/tests/wire.cpp +++ b/qschematic/wire_system/test/tests/wire.cpp @@ -19,10 +19,10 @@ TEST_SUITE("Wire") SUBCASE("Point can be added") { // Make sure the points are correct - REQUIRE(wire->points_count() == 3); - REQUIRE(wire->points().at(0) == QPointF(0, 10)); - REQUIRE(wire->points().at(1) == QPointF(23.2, 100)); - REQUIRE(wire->points().at(2) == QPointF(-123.4, 0.23)); + REQUIRE_EQ(wire->points_count(), 3); + REQUIRE_EQ(wire->points().at(0), QPointF(0, 10)); + REQUIRE_EQ(wire->points().at(1), QPointF(23.2, 100)); + REQUIRE_EQ(wire->points().at(2), QPointF(-123.4, 0.23)); } SUBCASE("Points can be removed") @@ -30,9 +30,9 @@ TEST_SUITE("Wire") wire->remove_point(1); // Make sure the points has been removed - REQUIRE(wire->points_count() == 2); - REQUIRE(wire->points().at(0) == QPointF(0, 10)); - REQUIRE(wire->points().at(1) == QPointF(-123.4, 0.23)); + REQUIRE_EQ(wire->points_count(), 2); + REQUIRE_EQ(wire->points().at(0), QPointF(0, 10)); + REQUIRE_EQ(wire->points().at(1), QPointF(-123.4, 0.23)); } } @@ -45,11 +45,11 @@ TEST_SUITE("Wire") wire->append_point(QPointF(1000, 10)); wire->append_point(QPointF(1000, 10)); - REQUIRE(wire->points_count() == 4); + REQUIRE_EQ(wire->points_count(), 4); wire->simplify(); - REQUIRE(wire->points_count() == 2); + REQUIRE_EQ(wire->points_count(), 2); } TEST_CASE("Wires can be moved") @@ -81,29 +81,29 @@ TEST_SUITE("Wire") wire1->move(QVector2D(1, -1)); // Make sure the first wire has moved correctly - REQUIRE(wire1->points().at(0).toPointF() == QPointF(1, 9)); - REQUIRE(wire1->points().at(1).toPointF() == QPointF(6, 9)); - REQUIRE(wire1->points().at(2).toPointF() == QPointF(6, 4)); - REQUIRE(wire1->points().at(3).toPointF() == QPointF(16, 4)); + CHECK_EQ(wire1->points().at(0).toPointF(), QPointF(1, 9)); + CHECK_EQ(wire1->points().at(1).toPointF(), QPointF(6, 9)); + CHECK_EQ(wire1->points().at(2).toPointF(), QPointF(6, 4)); + CHECK_EQ(wire1->points().at(3).toPointF(), QPointF(16, 4)); // Make sure the second wire stayed on the first one - REQUIRE(wire2->points().at(0).toPointF() == QPointF(11, 4)); - REQUIRE(wire2->points().at(1).toPointF() == QPointF(11, 10)); - REQUIRE(wire2->points().at(2).toPointF() == QPointF(15, 10)); + CHECK_EQ(wire2->points().at(0).toPointF(), QPointF(11, 4)); + CHECK_EQ(wire2->points().at(1).toPointF(), QPointF(11, 10)); + CHECK_EQ(wire2->points().at(2).toPointF(), QPointF(15, 10)); // Move the second wire wire2->move(QVector2D(2, 1)); // Make sure the first wire hasn't changed - REQUIRE(wire1->points().at(0).toPointF() == QPointF(1, 9)); - REQUIRE(wire1->points().at(1).toPointF() == QPointF(6, 9)); - REQUIRE(wire1->points().at(2).toPointF() == QPointF(6, 4)); - REQUIRE(wire1->points().at(3).toPointF() == QPointF(16, 4)); + CHECK_EQ(wire1->points().at(0).toPointF(), QPointF(1, 9)); + CHECK_EQ(wire1->points().at(1).toPointF(), QPointF(6, 9)); + CHECK_EQ(wire1->points().at(2).toPointF(), QPointF(6, 4)); + CHECK_EQ(wire1->points().at(3).toPointF(), QPointF(16, 4)); // Make sure the second wire has moved and is still on the first one - REQUIRE(wire2->points().at(0).toPointF() == QPointF(11, 4)); - REQUIRE(wire2->points().at(1).toPointF() == QPointF(11, 11)); - REQUIRE(wire2->points().at(2).toPointF() == QPointF(17, 11)); + CHECK_EQ(wire2->points().at(0).toPointF(), QPointF(11, 4)); + CHECK_EQ(wire2->points().at(1).toPointF(), QPointF(11, 11)); + CHECK_EQ(wire2->points().at(2).toPointF(), QPointF(17, 11)); } TEST_CASE("point_is_on_wire()") @@ -118,22 +118,22 @@ TEST_SUITE("Wire") manager.add_wire(wire); // These points are on the wire - REQUIRE(wire->point_is_on_wire(QPointF(10, 20))); - REQUIRE(wire->point_is_on_wire(QPointF(10, 10))); - REQUIRE(wire->point_is_on_wire(QPointF(15, 10))); - REQUIRE(wire->point_is_on_wire(QPointF(12.34, 10.01))); - REQUIRE(wire->point_is_on_wire(QPointF(20.01, 10))); - REQUIRE(wire->point_is_on_wire(QPointF(6, 8))); - REQUIRE(wire->point_is_on_wire(QPointF(8.2345, 3.531))); + CHECK(wire->point_is_on_wire(QPointF(10, 20))); + CHECK(wire->point_is_on_wire(QPointF(10, 10))); + CHECK(wire->point_is_on_wire(QPointF(15, 10))); + CHECK(wire->point_is_on_wire(QPointF(12.34, 10.01))); + CHECK(wire->point_is_on_wire(QPointF(20.01, 10))); + CHECK(wire->point_is_on_wire(QPointF(6, 8))); + CHECK(wire->point_is_on_wire(QPointF(8.2345, 3.531))); // These points are not on the wire - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(-10, -100))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(5, 5))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(6, 11))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(15, 15))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(15, 11))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(15, 10.1))); - REQUIRE_FALSE(wire->point_is_on_wire(QPointF(15, 9.9))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(-10, -100))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(5, 5))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(6, 11))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(15, 15))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(15, 11))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(15, 10.1))); + CHECK_FALSE(wire->point_is_on_wire(QPointF(15, 9.9))); } TEST_CASE("move_point_by(): Move points while making sure the angles are preserved") @@ -154,14 +154,14 @@ TEST_SUITE("Wire") wire->move_point_by(0, QVector2D(0, -20)); // Make sure the first two points moved - REQUIRE(wire->points().at(0).toPointF() == QPointF(0, 60)); - REQUIRE(wire->points().at(1).toPointF() == QPointF(40, 60)); + CHECK_EQ(wire->points().at(0).toPointF(), QPointF(0, 60)); + CHECK_EQ(wire->points().at(1).toPointF(), QPointF(40, 60)); // Make sure the other points didn't move - REQUIRE(wire->points().at(2).toPointF() == QPointF(40, 0)); - REQUIRE(wire->points().at(3).toPointF() == QPointF(20, 0)); - REQUIRE(wire->points().at(4).toPointF() == QPointF(20, 40)); - REQUIRE(wire->points().at(5).toPointF() == QPointF(80, 40)); + CHECK_EQ(wire->points().at(2).toPointF(), QPointF(40, 0)); + CHECK_EQ(wire->points().at(3).toPointF(), QPointF(20, 0)); + CHECK_EQ(wire->points().at(4).toPointF(), QPointF(20, 40)); + CHECK_EQ(wire->points().at(5).toPointF(), QPointF(80, 40)); } SUBCASE("Move a point in the middle of the wire") @@ -170,14 +170,14 @@ TEST_SUITE("Wire") wire->move_point_by(4, QVector2D(-20, 20)); // Make sure the points that are not affected by this haven't moved - REQUIRE(wire->points().at(0).toPointF() == QPointF(0, 80)); - REQUIRE(wire->points().at(1).toPointF() == QPointF(40, 80)); - REQUIRE(wire->points().at(2).toPointF() == QPointF(40, 0)); + CHECK_EQ(wire->points().at(0).toPointF(), QPointF(0, 80)); + CHECK_EQ(wire->points().at(1).toPointF(), QPointF(40, 80)); + CHECK_EQ(wire->points().at(2).toPointF(), QPointF(40, 0)); // Make the point and its adjacent points have moved - REQUIRE(wire->points().at(3).toPointF() == QPointF(0, 0)); - REQUIRE(wire->points().at(4).toPointF() == QPointF(0, 60)); - REQUIRE(wire->points().at(5).toPointF() == QPointF(80, 60)); + CHECK_EQ(wire->points().at(3).toPointF(), QPointF(0, 0)); + CHECK_EQ(wire->points().at(4).toPointF(), QPointF(0, 60)); + CHECK_EQ(wire->points().at(5).toPointF(), QPointF(80, 60)); } } } \ No newline at end of file