-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathtest_test.jl
42 lines (32 loc) · 1.17 KB
/
test_test.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# test file to test testing
# run this with julia -L extras/test.jl -e "tests(\"test/test_test.jl\")"
load("nearequal.jl")
test_context("Testing test tests")
# setup goes here
test_group("string tests")
@test strip("\t hi \n") == "hi"
@testfails strip("\t this should fail \n") == "hi"
test_group("numeric tests")
@test isapprox(.1+.1+.1, .3)
@testfails isapprox(.1+.1+.1, .4)
test_group("array tests")
a = Array(Float64, 2, 2, 2, 2, 2)
a[1,1,1,1,1] = 10
@test a[1,1,1,1,1] == 10
@testfails a[1,1,1,1,1] == 2
test_group("random tests")
@test rand() != rand() # not very likely to fail
@testfails rand() == rand() # very likely to fail
test_group("exception tests")
@testfails complex(1,2) > 0 # fail
@test throws_exception(complex(1,2) > 0, MethodError)
@testfails throws_exception(complex(1,2) > 0, SystemError)
test_group("printing tests")
@test sprint(show, :(1+2)) == "+(1,2)"
@test prints(print_joined, ([1,2,3], " : "), "1 : 2 : 3") # prints is a helper
@testfails prints(print_joined, ([1,2,3], " ! "), "1 : 2 : 3")
test_group("performance tests")
fib(n) = n < 2 ? n : fib(n-1) + fib(n-2)
@test fib(20) == 6765
@testfails takes_less_than(fib(20), 1e-6)
# shutdown goes here