@instructure/quiz-interactions
Version:
A React UI component Library for quiz interaction types.
215 lines (199 loc) • 6.04 kB
JavaScript
import {combination, baseNCombination, cartesianProduct, identityMatrix} from '../combinatorics'
describe('Combinatorics', () => {
describe('combination', () => {
it('should return a correct matrix for arguments ([0], 0))', () => {
expect(combination([0], 0)).toEqual([])
})
it('should return a correct matrix for arguments ([], 10))', () => {
expect(combination([], 10)).toEqual([])
})
it('should return a correct matrix for arguments ([1], 3)', () => {
expect(combination([1], 3)).toEqual([[1, 1, 1]])
})
it('should return a correct matrix for arguments ([0, 1, 2, 3], 1)', () => {
expect(combination([0, 1, 2, 3], 1)).toEqual([[0], [1], [2], [3]])
})
it('should return a correct matrix for arguments ([0, 1], 2)', () => {
expect(combination([0, 1], 2)).toEqual([
[],
[],
[],
])
})
it('should return a correct matrix for arguments ([0, 1], 3)', () => {
expect(combination([0, 1], 3)).toEqual([
[],
[],
[],
[],
])
})
it('should return a correct matrix for arguments ([0, 1, 2], 3)', () => {
expect(combination([0, 1, 2], 3)).toEqual([
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
])
})
})
describe('baseNCombination', () => {
it('should return a correct matrix for arguments ([0], 0))', () => {
expect(baseNCombination([0], 0)).toEqual([])
})
it('should return a correct matrix for arguments ([], 10))', () => {
expect(baseNCombination([], 10)).toEqual([])
})
it('should return a correct matrix for arguments ([1], 3))', () => {
expect(baseNCombination([1], 3)).toEqual([[1, 1, 1]])
})
it('should return a correct matrix for arguments ([0, 1, 2, 3], 1))', () => {
expect(baseNCombination([0, 1, 2, 3], 1)).toEqual([[0], [1], [2], [3]])
})
it('should return a correct matrix for arguments ([0, 1], 2))', () => {
expect(baseNCombination([0, 1], 2)).toEqual([
[],
[],
[],
[],
])
})
it('should return a correct matrix for arguments ([0, 1], 3))', () => {
expect(baseNCombination([0, 1], 3)).toEqual([
[],
[],
[],
[],
[],
[],
[],
[],
])
})
it('should return a correct matrix for arguments ([0, 1, 2], 3))', () => {
expect(baseNCombination([0, 1, 2], 3)).toEqual([
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
])
})
})
describe('cartesianProduct', () => {
it('should return a correct product for arguments ([], [])).', () => {
expect(cartesianProduct([], [])).toEqual([])
})
it('should return a correct product for arguments ([1], [])).t', () => {
expect(cartesianProduct([1], [])).toEqual([])
})
it("should return a correct product for arguments ([1, 2], ['a', 'b'])", () => {
expect(cartesianProduct([1, 2], ['a', 'b'])).toEqual([
[],
[],
[],
[],
])
})
it("should return a correct product for arguments ([1, 2], ['a', 'b'])", () => {
expect(cartesianProduct([1, 2], ['a', 'b'])).toEqual([
[],
[],
[],
[],
])
})
it("should return a correct product for arguments ([1], ['a', 'b', 'c'])", () => {
expect(cartesianProduct([1], ['a', 'b', 'c'])).toEqual([
[],
[],
[],
])
})
it("should return a correct product for arguments ([0, 1], ['a', 'b', 'c'])", () => {
expect(cartesianProduct([0, 1], ['a', 'b', 'c'])).toEqual([
[],
[],
[],
[],
[],
[],
])
})
it("should return a correct product for arguments ([0, 1], ['a', 'b'], [5, 6])", () => {
expect(cartesianProduct([0, 1], ['a', 'b'], [5, 6])).toEqual([
[],
[],
[],
[],
[],
[],
[],
[],
])
})
})
describe('identityMatrix', () => {
it('should return a correct identity for arguments ([0, 1], 1)', () => {
expect(identityMatrix([1, 0], 1)).toEqual([[1]])
})
it('should return a correct product for arguments ([1, 0], 0)).', () => {
expect(identityMatrix([1, 0], 0)).toEqual([])
})
it('should return a correct product for arguments ([1, 0], 2)).', () => {
expect(identityMatrix([1, 0], 2)).toEqual([
[],
[],
])
})
it('should have default arguments', () => {
expect(identityMatrix([], 2)).toEqual([
[],
[],
])
})
it('should return a correct product for arguments ([4, 10], 3)).', () => {
expect(identityMatrix([4, 10], 3)).toEqual([
[],
[],
[],
])
})
it("should return a correct product for arguments ([null, 'NULL'], 4)).", () => {
expect(identityMatrix([null, 'NULL'], 4)).toEqual([
[],
['NULL', null, 'NULL', 'NULL'],
['NULL', 'NULL', null, 'NULL'],
['NULL', 'NULL', 'NULL', null],
])
})
})
})