Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/condecon/adaptivetesting int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
condecon committed Jan 4, 2025
2 parents 30ac520 + 1969d8f commit 836fdec
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ For more information, please consult the documentation for the ``AdaptiveTest``

## Documentation
Extensive documentation of all programm code is available at [`/documentation`](/documentation).


# ToDo:

- 4PL Model
- ML
- Item Bank
- Test Information
- Implementations

- Bayes Modal
- Change AdaptiveTesting stucture
2 changes: 1 addition & 1 deletion adaptivetesting/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .__algorithm_exception import AlgorithmException
from .__item_pool import ItemPool
from .__item_selection_exception import ItemSelectionException
from .__test_item import TestItem, load_test_items_from_list
from .__test_item import TestItem, load_test_items_from_list, load_test_items_from_dict
from .__test_result import TestResult

73 changes: 70 additions & 3 deletions adaptivetesting/models/__test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@


class TestItem:
"""Representation of a test item in the item pool.
The format is equal to the implementation in catR.
"""
def __init__(self):
"""Representation of a test item in the item pool.
The format is equal to the implementation in catR.
## Properties:
- a (float):
- b (float): difficulty
- c (float):
- d (float):
"""
self.id: int | None = None
self.a: float = 1
self.b: float = float("nan")
self.c: float = 0
self.d: float = 1

def as_dict(self) -> dict[str, float]:
return {
"a": self.a,
"b": self.b,
"c": self.c,
"d": self.d
}


def load_test_items_from_list(source: List[float]) -> List[TestItem]:
Expand All @@ -31,3 +46,55 @@ def load_test_items_from_list(source: List[float]) -> List[TestItem]:
items.append(item)

return items

def load_test_items_from_dict(source: dict[str, List[float]]) -> List[TestItem]:
"""Creates test items from a dictionary.
The dictionary has to have the following keys:
- a
- b
- c
- d
each containing a list of float.
Args:
source (dict[str, List[float]]): item pool dictionary
Returns:
List[TestItem]: item pool
"""
a = source.get("a")
b = source.get("b")
c = source.get("c")
d = source.get("d")

# check none
if a is None:
raise ValueError("a cannot be None")

if b is None:
raise ValueError("b cannot be None")

if c is None:
raise ValueError("c cannot be None")

if d is None:
raise ValueError("d cannot be None")

# check if a, b, c, and d have the same length
if not (len(a) == len(b) == len(c) == len(d)):
raise ValueError("All lists in the source dictionary must have the same length")

n_items = len(b)
items: List[TestItem] = []
for i in range(n_items):
item = TestItem()
item.a = a[i]
item.b = b[i]
item.c = c[i]
item.d = d[i]

items.append(item)

return items

48 changes: 48 additions & 0 deletions adaptivetesting/tests/test_load_test_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from unittest import TestCase
from ..models import TestItem, load_test_items_from_dict

class TestLoadTestItems(TestCase):
def __init__(self, methodName = "runTest"):
super().__init__(methodName)
self.item1 = TestItem()
self.item1.a = 0.9
self.item1.b = 5
self.item1.c = 0.9

self.item2 = TestItem()
self.item2.a = 1.9
self.item2.b = 3
self.item2.c = 1.9

def test_load_test_items_from_dict_success(self):
source_dictionary: dict[str, list[float]] = {
"a": [0.9, 1.9],
"b": [5, 3],
"c": [0.9, 1.9],
"d": [1, 1]
}

generated = load_test_items_from_dict(source_dictionary)

self.assertEqual([self.item1.as_dict(), self.item2.as_dict()], [i.as_dict() for i in generated])

def test_load_test_items_from_dict_error_none(self):
source_dictionary: dict[str, list[float]] = {
"a": [0.9, 1.9],
"b": [5, 3],
"c": [0.9, 1.9],
}

with self.assertRaises(ValueError):
load_test_items_from_dict(source_dictionary)

def test_load_test_items_from_dict_error_length(self):
source_dictionary: dict[str, list[float]] = {
"a": [0.9, 1.9],
"b": [5, 3],
"c": [0.9, 1.9],
"d": [1]
}

with self.assertRaises(ValueError):
load_test_items_from_dict(source_dictionary)

0 comments on commit 836fdec

Please sign in to comment.