-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Add test case for class of road network
- Loading branch information
Showing
6 changed files
with
133 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
test_that("`create_road_network.sf` works with valid input", { | ||
road_network <- create_road_network(sample_roads) | ||
|
||
# Check the structure of the road network | ||
expect_s3_class(road_network, "road_network") | ||
expect_contains(names(road_network), c("graph", "nodes", "links", "roads")) | ||
expect_equal(nrow(road_network$nodes), 10) | ||
expect_equal(nrow(road_network$links), 10) | ||
|
||
# Check the directed property | ||
expect_false(is_directed(road_network$graph)) | ||
|
||
# Check the plot function | ||
expect_silent(plot(road_network)) | ||
}) | ||
|
||
test_that("`create_road_network.sf` works with directed input", { | ||
road_network <- create_road_network(sample_roads, directed = TRUE) | ||
|
||
# Check the structure of the road network | ||
expect_s3_class(road_network, "road_network") | ||
expect_contains(names(road_network), c("graph", "nodes", "links", "roads")) | ||
expect_equal(nrow(road_network$nodes), 10) | ||
expect_equal(nrow(road_network$links), 10) | ||
|
||
# Check the directed property | ||
expect_true(is_directed(road_network$graph)) | ||
|
||
# Check the plot function | ||
expect_silent(plot(road_network, mode = "graph")) | ||
}) | ||
|
||
test_that("`create_road_network.sf` works with events", { | ||
road_network <- create_road_network(sample_roads, events = sample_accidents) | ||
|
||
# Check the structure of the road network | ||
expect_s3_class(road_network, "road_network") | ||
expect_contains(names(road_network), | ||
c("graph", "nodes", "links", "roads", "events")) | ||
expect_equal(nrow(road_network$nodes), 10) | ||
expect_equal(nrow(road_network$links), 10) | ||
expect_equal(nrow(road_network$events), 10) | ||
|
||
# Check the plot function | ||
expect_silent(plot(road_network, mode = "event")) | ||
}) | ||
|
||
test_that("`print.road_network` works", { | ||
road_network <- create_road_network(sample_roads) | ||
|
||
# Check the print function | ||
expect_output(print(road_network), "Road network") | ||
expect_output(print(road_network), "Nodes:") | ||
expect_output(print(road_network), "Links:") | ||
}) | ||
|
||
test_that("`summary.road_network` works", { | ||
road_network <- create_road_network(sample_roads) | ||
|
||
# Check the summary function | ||
expect_output(summary(road_network), "Road network summary") | ||
expect_output(summary(road_network), "Number of nodes") | ||
expect_output(summary(road_network), "Number of links") | ||
}) | ||
|
||
test_that("`summary.road_network` works", { | ||
road_network <- create_road_network(sample_roads) | ||
|
||
# Check the summary function | ||
expect_output(summary(road_network), "Road network summary") | ||
expect_output(summary(road_network), "Number of nodes") | ||
expect_output(summary(road_network), "Number of links") | ||
}) | ||
|
||
test_that("`plot.road_network` throw error with event mode and no events", { | ||
road_network <- create_road_network(sample_roads) | ||
|
||
# Check the plot function | ||
expect_error(plot(road_network, mode = "event"), | ||
"no events assigned to the road network") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
test_that("`create_spatiotemporal_event` works with valid input", { | ||
spatiotemporal_events <- create_spatiotemporal_event(sample_accidents) | ||
|
||
# Check the structure of the spatiotemporal events | ||
expect_s3_class(spatiotemporal_events, "spatiotemporal_event") | ||
expect_equal(attr(spatiotemporal_events, "time_column"), "time") | ||
expect_equal(attr(spatiotemporal_events, "time_format"), "%H") | ||
}) | ||
|
||
test_that("`print.spatiotemporal_event` prints the correct information", { | ||
spatiotemporal_events <- create_spatiotemporal_event(sample_accidents) | ||
output <- capture.output(print(spatiotemporal_events)) | ||
|
||
expect_equal(output[1], | ||
"Spatiotemporal event collection with 10 events and 3 fields") | ||
expect_equal(output[2], "Geometry type: POINT") | ||
expect_equal(output[3], "Time column: time") | ||
expect_equal(output[4], "Time format: %H") | ||
expect_equal(output[5], "Data:") | ||
expect_equal(output[7], "1 ac_0001 18 Sunny Minor POINT (1 1)") | ||
expect_equal(output[11], "5 ac_0005 7 Rainy Minor POINT (5.9 1.1)") | ||
expect_equal(output[12], "... 5 more events") | ||
# Check the print function | ||
expect_output(print(spatiotemporal_events), | ||
"Spatiotemporal event collection with 10 events and 3 fields") | ||
expect_output(print(spatiotemporal_events), "Geometry type: POINT") | ||
expect_output(print(spatiotemporal_events), "Time column: time") | ||
expect_output(print(spatiotemporal_events), "Time format: %H") | ||
expect_output(print(spatiotemporal_events), "Data:") | ||
expect_output(print(spatiotemporal_events), "\\.\\.\\. 5 more events") | ||
}) |