-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
35 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name = "L6Testing" | ||
uuid = "44c933c6-7d10-4379-b2cf-b211c6f3d331" | ||
uuid = "12a8c696-9afa-4891-b56f-a95e8a68aa4d" | ||
authors = ["Mauro Werder <[email protected]>"] | ||
version = "0.1.0" |
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,10 +1,20 @@ | ||
[![CI action](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/actions/workflows/ci.yml) | ||
|
||
# Showcase unit and integration testing | ||
|
||
[![CI action](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing-subfolder.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing-subfolder.jl/actions/workflows/CI.yml) | ||
## This demonstrates how to use CI for a Julia project in a subfolder | ||
|
||
https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing-subfolder.jl/actions/workflows/CI.yml/badge.svg | ||
This is for Lecture 6 of course https://pde-on-gpu.vaw.ethz.ch | ||
|
||
This is for Lecture 7 of course | ||
https://eth-vaw-glaciology.github.io/course-101-0250-00/ | ||
It demonstrates a typical work-flow of mine which I committed such | ||
that commit history retraces that workflow: | ||
- start coding ([repo state](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/tree/8d3d875991e3010216b321413f34cb7ee01b8aa8)) | ||
- sprinkle a reference test within the script itself ([script | ||
state](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/blob/580eebd9287fb7c547520b3e2863a3ce599e8207/scripts/car_travel.jl)) | ||
- refactor and sprinkle a unit-test within the script itself ([script | ||
state](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/blob/33b669969b1227289b1059b9ce01baf3ced349e1/scripts/car_travel.jl)) | ||
- move tests to `test/` directory | ||
([runtests.jl](https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/blob/5b41f800039f77f4b1024393180733b396ee3c09/test/runtests.jl)) | ||
|
||
It demonstrates how to use CI for a Julia project in a subfolder. | ||
Here a link to the commits: | ||
https://github.com/eth-vaw-glaciology/course-101-0250-00-L6Testing.jl/commits/master |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ module L6Testing | |
|
||
greet() = print("Hello World!") | ||
|
||
end # module | ||
end # module L6Testing |
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,4 +1,2 @@ | ||
[deps] | ||
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" | ||
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
Binary file not shown.
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,35 +1,16 @@ | ||
using Test, ReferenceTests, BSON | ||
using Test | ||
|
||
include("../scripts/car_travels.jl") | ||
include("../scripts/car_travel.jl") | ||
|
||
## Unit tests | ||
@testset "update_position" begin | ||
@test update_position(0.0, 10, 1, 1, 200)[1] ≈ 10.0 | ||
@test update_position(0.0, 10, 1, 1, 200)[2] == 1 | ||
|
||
@test update_position(0.0, 10, -1, 1, 200)[1] ≈ -10.0 | ||
@test update_position(0.0, 10, -1, 1, 200)[2] == 1 | ||
|
||
@test update_position(0.0, 10, -1, 1, 200)[1] ≈ -10.0 | ||
@test update_position(0.0, 10, -1, 1, 200)[2] == 1 | ||
end | ||
|
||
|
||
## Reference Tests with ReferenceTests.jl | ||
# We put both arrays X and T into a BSON.jl and then compare them | ||
|
||
"Compare all dict entries" | ||
comp(d1, d2) = keys(d1) == keys(d2) && | ||
all([ v1≈v2 for (v1,v2) in zip(values(d1), values(d2))]) | ||
|
||
# run the model | ||
T, X = car_travel_1D() | ||
|
||
# Test just at some random indices. As for larger models, | ||
# storing the full output array would create really large files! | ||
inds = [18, 27, 45, 68, 71, 71, 102, 110, 123, 144] | ||
# a unit test | ||
@test update_position(10, 0, 1, 123, 123) == (10, 1) | ||
|
||
# a reference test: | ||
# make inds with `sort(rand(1:length(X), 10) | ||
inds = [10, 28, 36, 37, 39, 69, 80, 96, 128, 135] | ||
# make vals with `X[inds]` | ||
vals = [101.69999999999999, 101.7, 11.300000000000018, 1.7763568394002505e-14, 1.7763568394002505e-14, 67.80000000000001, 33.90000000000002, 192.10000000000005, 146.9, 180.80000000000004] | ||
|
||
d = Dict(:X=> X[inds], :T=>T[inds]) | ||
@testset "Ref-tests" begin | ||
@test_reference "reftest-files/X.bson" d by=comp | ||
end | ||
@test all(vals .≈ X[inds]) |