Skip to content

Commit

Permalink
Add more clowder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richford committed Sep 19, 2024
1 parent fc72b04 commit 92a4d74
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/__tests__/clowder.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Cat } from '..';
import { Clowder, ClowderInput } from '../clowder';
import { MultiZetaStimulus, Zeta, ZetaCatMap } from '../type';
import { defaultZeta } from '../utils';
Expand Down Expand Up @@ -70,6 +71,23 @@ describe('Clowder Class', () => {
);
});

it.each`
property
${'theta'}
${'seMeasurement'}
${'nItems'}
${'resps'}
${'zetas'}
`("accesses the '$property' property of each cat", ({ property }) => {
clowder.updateAbilityEstimates(['cat1'], createStimulus('1'), [0]);
clowder.updateAbilityEstimates(['cat2'], createStimulus('1'), [1]);
const expected = {
cat1: clowder.cats['cat1'][property as keyof Cat],
cat2: clowder.cats['cat2'][property as keyof Cat],
};
expect(clowder[property as keyof Clowder]).toEqual(expected);
});

// test('should select next stimulus from validated stimuli', () => {
// const nextItem = clowder.updateCatAndGetNextItem({
// catToSelect: 'cat1',
Expand All @@ -95,7 +113,7 @@ describe('Clowder Class', () => {
// expect(nextItem).toEqual(createStimulus('1')); // Unvalidated item
// });

test('should throw error if items and answers have mismatched lengths', () => {
it('throws an error if items and answers have mismatched lengths', () => {
expect(() => {
clowder.updateCatAndGetNextItem({
catToSelect: 'cat1',
Expand All @@ -104,4 +122,21 @@ describe('Clowder Class', () => {
});
}).toThrow('Previous items and answers must have the same length.');
});

it('throws an error if catToSelect is invalid', () => {
expect(() => {
clowder.updateCatAndGetNextItem({
catToSelect: 'invalidCatName',
});
}).toThrow('Invalid Cat name. Expected one of cat1, cat2. Received invalidCatName.');
});

it('throws an error if any of catsToUpdate is invalid', () => {
expect(() => {
clowder.updateCatAndGetNextItem({
catToSelect: 'cat1',
catsToUpdate: ['invalidCatName', 'cat2'],
});
}).toThrow('Invalid Cat name. Expected one of cat1, cat2. Received invalidCatName.');
});
});
1 change: 1 addition & 0 deletions src/clowder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class Clowder {
// Validate all cat names
this._validateCatName(catToSelect);
catsToUpdate = Array.isArray(catsToUpdate) ? catsToUpdate : [catsToUpdate];

catsToUpdate.forEach((cat) => {
this._validateCatName(cat);
});
Expand Down

0 comments on commit 92a4d74

Please sign in to comment.