Last active
April 5, 2019 14:14
-
-
Save antimon2/9b8034ebc7ba7f2b55947dd397e8ea31 to your computer and use it in GitHub Desktop.
Julia v1.0 でユニットテスト ref: https://qiita.com/antimon2/items/5222f4f773bf1944b745
This file contains hidden or 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
(v1.0) pkg> generate FizzBuzzQuiz | |
Generating project FizzBuzzQuiz: | |
FizzBuzzQuiz/Project.toml | |
FizzBuzzQuiz/src/FizzBuzzQuiz.jl | |
(v1.0) pkg> activate FizzBuzzQuiz | |
(FizzBuzzQuiz) pkg> | |
This file contains hidden or 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
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `/path/to/FizzBuzzQuiz/Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Multiplication: Test Failed at /path/to/FizzBuzzQuiz/test/runtests.jl:12 | |
Expression: 2 * 3 == 5 | |
Evaluated: 6 == 5 | |
Stacktrace: | |
: 《中略》 | |
Test Summary: | Pass Fail Total | |
Calcuration | 3 1 4 | |
Addition | 2 2 | |
Multiplication | 1 1 2 | |
ERROR: LoadError: Some tests did not pass: 3 passed, 1 failed, 0 errored, 0 broken. | |
in expression starting at /path/to/FizzBuzzQuiz/test/runtests.jl:4 | |
ERROR: Package FizzBuzzQuiz errored during testing | |
This file contains hidden or 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
module HOGE | |
""" | |
greet() | |
# Sample | |
```jldoctest | |
julia> using HOGE; HOGE.greet() | |
"Hello World!" | |
``` """ | |
greet() = "Hello World!" | |
end |
This file contains hidden or 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
$ julia --project -e 'using Pkg;Pkg.test()' | |
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `path/to/FizzBuzzQuiz/Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Test Summary: | Pass Total | |
Fizz & Buzz | 9 9 | |
Test Summary: | Pass Total | |
Pezz | 12 12 | |
Test Summary: | Pass Total | |
Hozz | 5 5 | |
Testing FizzBuzzQuiz tests passed |
This file contains hidden or 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
$ pwd | |
/path/to/FizzBuzzQuiz | |
$ julia --project | |
_ | |
_ _ _(_)_ | Documentation: https://docs.julialang.org | |
(_) | (_) (_) | | |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | |
| | | | | | |/ _` | | | |
| | |_| | | | (_| | | Version 1.0.1 (2018-09-29) | |
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release | |
|__/ | | |
julia> # ']' キーで Pkg REPL-mode に移行 | |
(FizzBuzzQuiz) pkg>test | |
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Testing FizzBuzzQuiz tests passed | |
This file contains hidden or 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
$ pwd | |
/path/to/FizzBuzzQuiz | |
$ julia --project -e 'using Pkg;Pkg.test()' | |
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Testing FizzBuzzQuiz tests passed | |
This file contains hidden or 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
FizzBuzzQuiz) pkg> test | |
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `/path/to/FizzBuzzQuiz/Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Test Summary: | Pass Total | |
Addition | 2 2 | |
Test Summary: | Pass Total | |
Multiplication | 2 2 | |
Testing FizzBuzzQuiz tests passed | |
This file contains hidden or 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
(FizzBuzzQuiz) pkg> test | |
Updating registry at `~/.julia/registries/General` | |
Updating git-repo `https://github.com/JuliaRegistries/General.git` | |
Resolving package versions... | |
Updating `/path/to/FizzBuzzQuiz/Project.toml` | |
[no changes] | |
Testing FizzBuzzQuiz | |
Resolving package versions... | |
Test Summary: | Pass Total | |
Addition | 2 2 | |
Multiplication: Test Failed at /path/to/FizzBuzzQuiz/test/runtests.jl:11 | |
Expression: 2 * 3 == 5 | |
Evaluated: 6 == 5 | |
Stacktrace: | |
: 《中略》 | |
Test Summary: | Pass Fail Total | |
Multiplication | 1 1 2 | |
ERROR: LoadError: Some tests did not pass: 1 passed, 1 failed, 0 errored, 0 broken. | |
in expression starting at /path/to/FizzBuzzQuiz/test/runtests.jl:9 | |
ERROR: Package FizzBuzzQuiz errored during testing | |
This file contains hidden or 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
@testset "Fizz & Buzz" begin | |
# @test fizz(1) == 1 | |
@test 1 |> fizz == 1 | |
@test 3 |> fizz == "Fizz" | |
@test 1 |> buzz == 1 | |
@test 5 |> buzz == "Buzz" | |
# @test buzz(fizz(1)) == 1 | |
@test 1 |> fizz |> buzz == 1 | |
@test 3 |> fizz |> buzz == "Fizz" | |
@test 5 |> fizz |> buzz == "Buzz" | |
@test 15 |> fizz |> buzz == "FizzBuzz" | |
@test 15 |> buzz |> fizz == "BuzzFizz" | |
end |
This file contains hidden or 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
module FizzBuzzQuiz | |
greet() = print("Hello World!") | |
end # module |
This file contains hidden or 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
@testset "Hozz" begin | |
@test 13 |> fizz |> buzz |> hozz == "Aho" | |
@test 3 |> fizz |> buzz |> hozz == "FizzAho" | |
@test 35 |> fizz |> buzz |> hozz == "BuzzAho" | |
@test 30 |> fizz |> buzz |> hozz == "FizzBuzzAho" | |
@test 30 |> hozz |> buzz |> fizz == "AhoBuzzFizz" | |
end |
This file contains hidden or 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
@testset "Pezz" begin | |
# @test pezz(buzz(fizz(7))) == "Pezz" | |
@test 7 |> fizz |> buzz |> pezz == "Pezz" | |
@test 21 |> fizz |> buzz |> pezz == "FizzPezz" | |
@test 35 |> fizz |> buzz |> pezz == "BuzzPezz" | |
@test 105 |> fizz |> buzz |> pezz == "FizzBuzzPezz" | |
@test 105 |> fizz |> pezz |> buzz == "FizzPezzBuzz" | |
@test 105 |> pezz |> buzz |> fizz == "PezzBuzzFizz" | |
# 以下も念のため | |
@test 1 |> fizz |> buzz |> pezz == 1 | |
@test 3 |> fizz |> buzz |> pezz == "Fizz" | |
@test 5 |> fizz |> buzz |> pezz == "Buzz" | |
@test 15 |> fizz |> buzz |> pezz == "FizzBuzz" | |
@test 15 |> buzz |> fizz |> pezz == "BuzzFizz" | |
@test 104 |> fizz |> buzz |> pezz == 104 | |
end |
This file contains hidden or 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
name = "FizzBuzzQuiz" | |
uuid = "21722cf0-b7d5-11e8-334b-05128eaae1be" | |
authors = ["antimon2 <[email protected]>"] | |
version = "0.1.0" | |
[deps] | |
[extras] | |
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |
[targets] | |
test = ["Test"] |
This file contains hidden or 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
using FizzBuzzQuiz | |
using Test | |
tests = ["fizz_buzz", "pezz", "hozz"] | |
for test = tests | |
# println("testing $test.jl...") | |
include("$test.jl") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment