Skip to content

Commit 0bb3741

Browse files
committed
Add item bank funcs to stateful + interface test
1 parent 73b933d commit 0bb3741

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

ext/TestExt.jl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ module TestExt
22

33
using Test
44
using ComputerAdaptiveTesting: Stateful
5+
using FittedItemBanks: AbstractItemBank, ItemResponse, resp
56

6-
export test_stateful_cat_1d_dich_ib
7+
export test_stateful_cat_1d_dich_ib, test_stateful_cat_item_bank_1d_dich_ib
78

89
function test_stateful_cat_1d_dich_ib(
910
cat::Stateful.StatefulCat,
@@ -66,9 +67,8 @@ function test_stateful_cat_1d_dich_ib(
6667
end
6768
end
6869

69-
Stateful.reset!(cat)
70-
7170
@testset "basic get_ability tests" begin
71+
Stateful.reset!(cat)
7272
Stateful.add_response!(cat, 1, false)
7373
Stateful.add_response!(cat, 2, true)
7474
ability = Stateful.get_ability(cat)
@@ -79,6 +79,7 @@ function test_stateful_cat_1d_dich_ib(
7979

8080
if supports_rollback
8181
@testset "rollback ability tests" begin
82+
Stateful.reset!(cat)
8283
Stateful.add_response!(cat, 1, false)
8384
ability1 = Stateful.get_ability(cat)
8485
Stateful.add_response!(cat, 2, true)
@@ -91,4 +92,22 @@ function test_stateful_cat_1d_dich_ib(
9192
end
9293
end
9394

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+
94113
end

src/Stateful.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Stateful
77

88
using DocStringExtensions
99

10-
using FittedItemBanks: AbstractItemBank, ResponseType
10+
using FittedItemBanks: AbstractItemBank, ResponseType, ItemResponse, resp
1111
using ..Aggregators: TrackedResponses, Aggregators
1212
using ..CatConfig: CatLoopConfig, CatRules
1313
using ..Responses: BareResponses, Response, Responses
@@ -124,6 +124,25 @@ but should attempt to interoperate with ComputerAdaptiveTesting.jl.
124124
"""
125125
function get_ability end
126126

127+
"""
128+
```julia
129+
$(FUNCTIONNAME)(config::StatefulCat)
130+
````
131+
132+
Return number of items in the current item bank.
133+
"""
134+
function item_bank_size end
135+
136+
"""
137+
```julia
138+
$(FUNCTIONNAME)(config::StatefulCat, index::IndexT, response::ResponseT, ability::AbilityT) -> Float
139+
````
140+
141+
Return the probability of a `response` to item at `index` for someone with
142+
a certain `ability` according to the IRT model backing the CAT.
143+
"""
144+
function item_response_function end
145+
127146
## Running the CAT
128147
function Sim.run_cat(cat_config::CatLoopConfig{RulesT},
129148
ib_labels = nothing) where {RulesT <: StatefulCat}
@@ -220,6 +239,16 @@ function get_ability(config::StatefulCatConfig)
220239
return (config.rules.ability_estimator(config.tracked_responses[]), nothing)
221240
end
222241

242+
function item_bank_size(config::StatefulCatConfig)
243+
return length(config.tracked_responses[].item_bank)
244+
end
245+
246+
function item_response_function(config::StatefulCatConfig, index, response, ability)
247+
item_bank = config.tracked_responses[].item_bank
248+
item_response = ItemResponse(item_bank, index)
249+
return resp(item_response, response, ability)
250+
end
251+
223252
## TODO: Implementation for MaterializedDecisionTree
224253

225254
end

test/stateful.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,6 @@
8888
4;
8989
supports_ranked_and_criteria = false,
9090
)
91+
TestExt.test_stateful_cat_item_bank_1d_dich_ib(cat_config, item_bank)
9192
end
9293
end

0 commit comments

Comments
 (0)