1
+ module TestExt
2
+
3
+ using Test
4
+ using ComputerAdaptiveTesting: Stateful
5
+ using FittedItemBanks: AbstractItemBank, ItemResponse, resp
6
+
7
+ export test_stateful_cat_1d_dich_ib, test_stateful_cat_item_bank_1d_dich_ib
8
+
9
+ function test_stateful_cat_1d_dich_ib (
10
+ cat:: Stateful.StatefulCat ,
11
+ item_bank_length;
12
+ supports_ranked_and_criteria = true ,
13
+ supports_rollback = true
14
+ )
15
+ if item_bank_length < 3
16
+ error (" Item bank length must be at least 3." )
17
+ end
18
+ @testset " response round trip" begin
19
+ responses_before = Stateful. get_responses (cat)
20
+ @test length (responses_before. indices) == 0
21
+ @test length (responses_before. values) == 0
22
+
23
+ Stateful. add_response! (cat, 1 , false )
24
+ Stateful. add_response! (cat, 2 , true )
25
+
26
+ responses_after_add = Stateful. get_responses (cat)
27
+ @test length (responses_after_add. indices) == 2
28
+ @test length (responses_after_add. values) == 2
29
+
30
+ Stateful. reset! (cat)
31
+ responses_after_reset = Stateful. get_responses (cat)
32
+ @test length (responses_after_reset. indices) == 0
33
+ @test length (responses_after_reset. values) == 0
34
+ end
35
+
36
+ # Test the next_item function
37
+ @testset " basic next_item tests" begin
38
+ Stateful. add_response! (cat, 1 , false )
39
+ Stateful. add_response! (cat, 2 , true )
40
+
41
+ item = Stateful. next_item (cat)
42
+ @test isa (item, Integer)
43
+ @test item >= 1
44
+ @test item >= 3
45
+ @test item <= item_bank_length
46
+ end
47
+
48
+ if supports_ranked_and_criteria
49
+ @testset " basic ranked/criteria tests" begin
50
+ items = Stateful. ranked_items (cat)
51
+ @test length (items) == item_bank_length
52
+
53
+ criteria = Stateful. item_criteria (cat)
54
+ @test length (criteria) == item_bank_length
55
+ end
56
+ end
57
+
58
+ if supports_rollback
59
+ @testset " basic rollback tests" begin
60
+ Stateful. reset! (cat)
61
+ Stateful. add_response! (cat, 1 , false )
62
+ Stateful. add_response! (cat, 2 , true )
63
+ Stateful. rollback! (cat)
64
+ responses_after_rollback = Stateful. get_responses (cat)
65
+ @test length (responses_after_rollback. indices) == 1
66
+ @test length (responses_after_rollback. values) == 1
67
+ end
68
+ end
69
+
70
+ @testset " basic get_ability tests" begin
71
+ Stateful. reset! (cat)
72
+ Stateful. add_response! (cat, 1 , false )
73
+ Stateful. add_response! (cat, 2 , true )
74
+ ability = Stateful. get_ability (cat)
75
+ @test isa (ability, Tuple)
76
+ @test length (ability) == 2
77
+ @test isa (ability[1 ], Float64)
78
+ end
79
+
80
+ if supports_rollback
81
+ @testset " rollback ability tests" begin
82
+ Stateful. reset! (cat)
83
+ Stateful. add_response! (cat, 1 , false )
84
+ ability1 = Stateful. get_ability (cat)
85
+ Stateful. add_response! (cat, 2 , true )
86
+ ability2 = Stateful. get_ability (cat)
87
+ Stateful. rollback! (cat)
88
+ @test Stateful. get_ability (cat) == ability1
89
+ Stateful. add_response! (cat, 2 , true )
90
+ @test Stateful. get_ability (cat) == ability2
91
+ end
92
+ end
93
+ end
94
+
95
+ function test_stateful_cat_item_bank_1d_dich_ib (
96
+ cat:: Stateful.StatefulCat ,
97
+ item_bank:: AbstractItemBank ,
98
+ points= [- .78 , 0.0 , .78 ],
99
+ margin= 0.05 ,
100
+ )
101
+ if length (item_bank) != Stateful. item_bank_size (cat)
102
+ error (" Item bank length does not match the cat's item bank size." )
103
+ end
104
+ for i in 1 : length (item_bank)
105
+ for point in points
106
+ cat_prob = Stateful. item_response_function (cat, i, true , point)
107
+ ib_prob = resp (ItemResponse (item_bank, i), true , point)
108
+ @test cat_prob ≈ ib_prob rtol= margin
109
+ end
110
+ end
111
+ end
112
+
113
+ end
0 commit comments