Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszkiba committed Oct 7, 2024
1 parent e81f053 commit 25d29c8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
9 changes: 4 additions & 5 deletions catmodel/grm/classes/grm.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ class grm extends model_multiparam {
public static function get_parameters_from_record(stdClass $record): array {

$difficulties = json_decode($record->json, true)['difficulties'];
$discrimination = round($record->discrimination, self::PRECISION);

return [
'discrimination' => round($discrimination, self::PRECISION),
'difficulties' => $difficulties,
'difficulty' => self::calculate_mean_difficulty(['difficulties' => $difficulties]),
];
}

Expand Down Expand Up @@ -103,14 +102,14 @@ public static function convert_vector_to_ip(array $vector, $fractions): array {
*
* This will have the following structure.
* [
* 'difficultiy': [fraction1: difficulty1, fraction2: difficulty2, ..., fractionk: difficultyk],
* 'discrimination': discrimination
* 'difficulty': 1.23,
* 'difficulties': [fraction1: difficulty1, fraction2: difficulty2, ..., fractionk: difficultyk],
* ]
*
* @return array
*/
public static function get_parameter_names(): array {
return ['discrimination', 'difficulties'];
return ['difficulty', 'difficulties'];

}

Expand Down
1 change: 1 addition & 0 deletions catmodel/grmgeneralized/classes/grmgeneralized.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function get_parameters_from_record(stdClass $record): array {
$discrimination = round($record->discrimination, self::PRECISION);

return [
'difficulty' => self::calculate_mean_difficulty(['difficulties' => $difficulties]),
'discrimination' => $discrimination,
'difficulties' => $difficulties,
];
Expand Down
1 change: 1 addition & 0 deletions catmodel/pcm/classes/pcm.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function get_parameters_from_record(stdClass $record): array {

return [
'intercepts' => $intercepts,
'difficulty' => round(self::calculate_mean_difficulty(['intercepts' => $intercepts]), self::PRECISION),
];
}

Expand Down
1 change: 1 addition & 0 deletions catmodel/pcmgeneralized/classes/pcmgeneralized.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function get_parameters_from_record(stdClass $record): array {
$discrimination = round($record->discrimination, self::PRECISION);

return [
'difficulty' => round(self::calculate_mean_difficulty(['intercepts' => $intercepts]), self::PRECISION),
'discrimination' => $discrimination,
'intercepts' => $intercepts,
];
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/simulation_multiparam.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ componentid;status;qtype;model;difficulty;discrimination;guessing;label;catscale
0;4;Multiple-Choice;raschbirnbaum;-4.45;5.92;0.0000;SIMA01-00;SimA01;Simulation|SimA;question;
0;4;Multiple-Choice;grmgeneralized;-4.57;5.22;0.0000;SIMA01-01;SimA01;Simulation|SimA;question;{"difficulties": {"0.00": 0.18, "0.33": 0.38, "0.66": 0.62, "1.00": 0.89}}
0;4;Multiple-Choice;raschbirnbaum;-3.86;0.99;0.0000;SIMA01-02;SimA01;Simulation|SimA;question;
0;4;Multiple-Choice;pcmgeneralized;-3.41;0.71;0.0000;SIMA01-03;SimA01;Simulation|SimA;question;{intercepts: {"0.00": 0.0, "0.33": 0.24, "0.66": 0.52, "1.00": 0.96}}
0;4;Multiple-Choice;pcmgeneralized;-3.41;0.71;0.0000;SIMA01-03;SimA01;Simulation|SimA;question;{"intercepts": {"0.00": 0.0, "0.33": 0.24, "0.66": 0.52, "1.00": 0.96}}
0;4;Multiple-Choice;raschbirnbaum;-4.08;0.7;0.0000;SIMA01-04;SimA01;Simulation|SimA;question;
0;4;Multiple-Choice;pcm;-3.71;1.81;0.0000;SIMA01-05;SimA01;Simulation|SimA;question;{intercepts: {"0.00": 0.0, "0.33": 0.21, "0.66": 0.52, "1.00": 0.91}}
0;4;Multiple-Choice;pcm;-0.99;3.39;0.0000;SIMA02-00;SimA02;Simulation|SimA;question;{intercepts: {"0.00": 0.0, "0.33": 0.22, "0.66": 0.58, "1.00": 0.92}}
0;4;Multiple-Choice;pcm;-0.19;3.01;0.0000;SIMA02-01;SimA02;Simulation|SimA;question;{intercepts: {"0.00": 0.0, "0.33": 0.23, "0.66": 0.54, "1.00": 0.94}}
0;4;Multiple-Choice;pcm;-3.71;1.81;0.0000;SIMA01-05;SimA01;Simulation|SimA;question;{"intercepts": {"0.00": 0.0, "0.33": 0.21, "0.66": 0.52, "1.00": 0.91}}
0;4;Multiple-Choice;pcm;-0.99;3.39;0.0000;SIMA02-00;SimA02;Simulation|SimA;question;{"intercepts": {"0.00": 0.0, "0.33": 0.22, "0.66": 0.58, "1.00": 0.92}}
0;4;Multiple-Choice;pcm;-0.19;3.01;0.0000;SIMA02-01;SimA02;Simulation|SimA;question;{"intercepts": {"0.00": 0.0, "0.33": 0.23, "0.66": 0.54, "1.00": 0.94}}
0;4;Multiple-Choice;grm;-1.28;5.61;0.0000;SIMA02-02;SimA02;Simulation|SimA;question;{"difficulties": {"0.00": 0.14, "0.33": 0.44, "0.66": 0.50, "1.00": 0.88}}
0;4;Multiple-Choice;grm;0.42;4.44;0.0000;SIMA02-03;SimA02;Simulation|SimA;question;{"difficulties": {"0.00": 0.15, "0.33": 0.43, "0.66": 0.59, "1.00": 0.87}}
0;4;Multiple-Choice;grm;-2.79;4.16;0.0000;SIMA02-04;SimA02;Simulation|SimA;question;{"difficulties": {"0.00": 0.16, "0.33": 0.42, "0.66": 0.57, "1.00": 0.86}}
Expand Down
10 changes: 6 additions & 4 deletions tests/local/model/model_item_param_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test_read_item_param_from_db(array $record, array $parameters):
}

/**
* Provide Data for test of save_or_update_testitem_in_db.
* Provide Data for test of test_read_item_param_from_db.
*
* @return array
*
Expand Down Expand Up @@ -98,6 +98,7 @@ public static function read_item_param_from_db_provider(): array {
'parameters' => [
'difficulties' => ['0.00' => 0.12, '0.33' => 0.35, '0.66' => 0.68, '1.00' => 0.83],
'discrimination' => 5.92,
'difficulty' => 0.59,
],
],
'grm' => [
Expand Down Expand Up @@ -179,6 +180,7 @@ public static function read_item_param_from_db_provider(): array {
'parameters' => [
'discrimination' => 2.1,
'intercepts' => ['0.000' => 0.0, '0.333' => 0.42, '0.666' => 0.57, '1.000' => 0.98],
'difficulty' => 0.7,
],
],
'pcm' => [
Expand All @@ -195,8 +197,8 @@ public static function read_item_param_from_db_provider(): array {
'json' => $pcmjson,
],
'parameters' => [
'difficulty' => 0.680,
'intercepts' => ['0.000' => 0.10, '0.333' => 0.48, '0.666' => 0.53, '1.000' => 0.88],
'difficulty' => 0.68,
],
],
];
Expand Down Expand Up @@ -238,15 +240,15 @@ public static function write_item_param_to_db_provider(): array {
],
]);
$pcmgeneralizedjson = json_encode([
'intercept' => [
'intercepts' => [
'0.000' => 0.00,
'0.333' => 0.42,
'0.666' => 0.57,
'1.000' => 0.98,
],
]);
$pcmjson = json_encode([
'intercept' => [
'intercepts' => [
'0.000' => 0.10,
'0.333' => 0.48,
'0.666' => 0.53,
Expand Down

0 comments on commit 25d29c8

Please sign in to comment.