Skip to content

Commit cbf0956

Browse files
authored
Merge pull request #16 from SyntaxSpirits/test/readme-examples
2 parents 1bd558b + dc1ba13 commit cbf0956

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project are documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
- Added executable specs for README usage examples to keep the documented Rasch, 2PL, 3PL, and missing-data flows aligned with the public API.
9+
710
### Changed
811
- Clarified that response data must be a `Matrix` or array of arrays containing only integer `0`, integer `1`, or `nil`; floats, strings, booleans, and other values are rejected.
912

spec/readme_examples_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
require "matrix"
5+
6+
RSpec.describe "README examples" do
7+
let(:data) do
8+
Matrix[
9+
[1, 0, 1],
10+
[0, 1, 0],
11+
[1, 1, 1]
12+
]
13+
end
14+
15+
it "runs the Rasch quick-start example" do
16+
model = IrtRuby::RaschModel.new(data)
17+
result = model.fit
18+
19+
expect(result[:abilities].size).to eq(data.row_count)
20+
expect(result[:difficulties].size).to eq(data.column_count)
21+
end
22+
23+
it "runs the 2PL and 3PL examples" do
24+
two_pl_result = IrtRuby::TwoParameterModel.new(data).fit
25+
three_pl_result = IrtRuby::ThreeParameterModel.new(data).fit
26+
27+
expect(two_pl_result[:abilities].size).to eq(data.row_count)
28+
expect(two_pl_result[:difficulties].size).to eq(data.column_count)
29+
expect(two_pl_result[:discriminations].size).to eq(data.column_count)
30+
31+
expect(three_pl_result[:abilities].size).to eq(data.row_count)
32+
expect(three_pl_result[:difficulties].size).to eq(data.column_count)
33+
expect(three_pl_result[:discriminations].size).to eq(data.column_count)
34+
expect(three_pl_result[:guessings].size).to eq(data.column_count)
35+
end
36+
37+
it "runs the missing-data example with array input" do
38+
data_with_missing = [
39+
[1, nil, 0],
40+
[nil, 1, 0],
41+
[0, 1, 1]
42+
]
43+
44+
model = IrtRuby::RaschModel.new(
45+
data_with_missing,
46+
max_iter: 300,
47+
learning_rate: 0.01,
48+
missing_strategy: :treat_as_incorrect
49+
)
50+
result = model.fit
51+
52+
expect(result[:abilities].size).to eq(data_with_missing.size)
53+
expect(result[:difficulties].size).to eq(data_with_missing.first.size)
54+
end
55+
end

0 commit comments

Comments
 (0)