Using: indgen_ut__define.pro

File indgen_ut__define.pro, 1.4 KB (added by mgalloy, 4 years ago)

Example of a test case

Line 
1; docformat = 'rst'
2
3;+
4; To create a test case just inherit from MGtestCase and create method with
5; names that start with "test". This test can be run with the command::
6;
7;    mgunit, cases='indgentest'
8;-
9
10
11;+
12; This test should pass the assertion and return 1 (i.e. success). Tests can
13; also return 0 or generate an error to indicate failure.
14;-
15function indgen_ut::test_basic
16  compile_opt strictarr
17 
18  a = indgen(5)
19  assert, array_equal(a, [0.0, 1.0, 2.0, 3.0, 4.0]), 'Correct elements'
20
21  return, 1
22end
23
24
25;+
26; This test fails because the assertion is wrong.
27;-
28function indgen_ut::test_fail_example
29  compile_opt strictarr
30 
31  a = indgen(5) 
32  assert, n_elements(a) eq 6, 'Wrong number of elements'
33
34  return, 1
35end
36
37
38;+
39; This is a test that will pass because the code of the test is supposed to
40; cause an error. To do this kind of test, use the "error_is_pass" batch file.
41;-
42function indgen_ut::test_error
43  compile_opt strictarr
44  @error_is_pass
45
46  a = indgen('string')
47
48  return, 0
49end
50
51
52;+
53; This is a test that will fail on an io error because of the use of the
54; "error_is_fail" batch file. IO errors don't normally cause a test to fail.
55;-
56function indgen_ut::test_baderror
57  compile_opt strictarr
58  @error_is_fail
59 
60  a = indgen('another_string')
61
62  return, 1
63end
64
65
66;+
67; Inherit from MGtestCase.
68;-
69pro indgen_ut__define
70  compile_opt strictarr
71 
72  define = { indgen_ut, inherits MGutTestCase }
73end