Skip to content

Commit

Permalink
tests: improve test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Tectu committed Jul 27, 2023
1 parent c624166 commit 51d4a68
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 102 deletions.
26 changes: 13 additions & 13 deletions qschematic/wire_system/test/tests/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
66 changes: 33 additions & 33 deletions qschematic/wire_system/test/tests/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ 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<wire_system::wire>();
wire2->append_point({10, 10});
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());
}

Expand All @@ -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")
Expand All @@ -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());
Expand Down Expand Up @@ -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") {
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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") {
Expand All @@ -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));
}
}

Expand All @@ -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);
}
}
14 changes: 7 additions & 7 deletions qschematic/wire_system/test/tests/nets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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));
}
}
Loading

0 comments on commit 51d4a68

Please sign in to comment.