UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

215 lines (199 loc) • 6.04 kB
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([ [0, 0], [0, 1], [1, 1], ]) }) it('should return a correct matrix for arguments ([0, 1], 3)', () => { expect(combination([0, 1], 3)).toEqual([ [0, 0, 0], [0, 0, 1], [0, 1, 1], [1, 1, 1], ]) }) it('should return a correct matrix for arguments ([0, 1, 2], 3)', () => { expect(combination([0, 1, 2], 3)).toEqual([ [0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 1], [0, 1, 2], [0, 2, 2], [1, 1, 1], [1, 1, 2], [1, 2, 2], [2, 2, 2], ]) }) }) 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([ [0, 0], [0, 1], [1, 0], [1, 1], ]) }) it('should return a correct matrix for arguments ([0, 1], 3))', () => { expect(baseNCombination([0, 1], 3)).toEqual([ [0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1], ]) }) it('should return a correct matrix for arguments ([0, 1, 2], 3))', () => { expect(baseNCombination([0, 1, 2], 3)).toEqual([ [0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 2, 0], [0, 2, 1], [0, 2, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1], [2, 2, 2], ]) }) }) 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([ [1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], ]) }) it("should return a correct product for arguments ([1, 2], ['a', 'b'])", () => { expect(cartesianProduct([1, 2], ['a', 'b'])).toEqual([ [1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'], ]) }) it("should return a correct product for arguments ([1], ['a', 'b', 'c'])", () => { expect(cartesianProduct([1], ['a', 'b', 'c'])).toEqual([ [1, 'a'], [1, 'b'], [1, 'c'], ]) }) it("should return a correct product for arguments ([0, 1], ['a', 'b', 'c'])", () => { expect(cartesianProduct([0, 1], ['a', 'b', 'c'])).toEqual([ [0, 'a'], [0, 'b'], [0, 'c'], [1, 'a'], [1, 'b'], [1, 'c'], ]) }) it("should return a correct product for arguments ([0, 1], ['a', 'b'], [5, 6])", () => { expect(cartesianProduct([0, 1], ['a', 'b'], [5, 6])).toEqual([ [0, 'a', 5], [0, 'a', 6], [0, 'b', 5], [0, 'b', 6], [1, 'a', 5], [1, 'a', 6], [1, 'b', 5], [1, 'b', 6], ]) }) }) 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([ [1, 0], [0, 1], ]) }) it('should have default arguments', () => { expect(identityMatrix([], 2)).toEqual([ [1, 0], [0, 1], ]) }) it('should return a correct product for arguments ([4, 10], 3)).', () => { expect(identityMatrix([4, 10], 3)).toEqual([ [4, 10, 10], [10, 4, 10], [10, 10, 4], ]) }) 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'], ['NULL', 'NULL', 'NULL', null], ]) }) }) })