Created
May 10, 2016 13:49
-
-
Save jemgold/a4372f279ed06c1fd3e776c138a4cb0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect'; | |
import { countByFrom, probablize } from 'src/MarkovMatrix'; | |
describe('MarkovMatrix', () => { | |
it('counts by from-state', () => { | |
const input = [ | |
['foo', 'bar'], | |
['foo', 'bar'], | |
['foo', 'bar'], | |
['foo', 'baz'], | |
['bar', 'baz'], | |
['bar', 'foo'], | |
['baz', 'bar'], | |
]; | |
const expected = { | |
foo: { | |
bar: 3, | |
baz: 1, | |
}, | |
bar: { | |
foo: 1, | |
baz: 1, | |
}, | |
baz: { | |
bar: 1, | |
}, | |
}; | |
expect(countByFrom(input)).toEqual(expected); | |
}); | |
it('probablizes from counts', () => { | |
const input = { | |
foo: { | |
bar: 3, | |
baz: 1, | |
}, | |
bar: { | |
foo: 1, | |
baz: 1, | |
}, | |
baz: { | |
bar: 1, | |
}, | |
}; | |
const expected = { | |
foo: { | |
bar: 0.75, | |
baz: 0.25, | |
}, | |
bar: { | |
foo: 0.5, | |
baz: 0.5, | |
}, | |
baz: { | |
bar: 1, | |
}, | |
}; | |
expect(probablize(input)).toEqual(expected); | |
}); | |
it('does the whole shebang', () => { | |
const input = [ | |
['foo', 'bar'], | |
['foo', 'bar'], | |
['foo', 'bar'], | |
['foo', 'baz'], | |
['bar', 'baz'], | |
['bar', 'foo'], | |
['baz', 'bar'], | |
]; | |
const expected = { | |
foo: { | |
bar: 0.75, | |
baz: 0.25, | |
}, | |
bar: { | |
foo: 0.5, | |
baz: 0.5, | |
}, | |
baz: { | |
bar: 1, | |
}, | |
}; | |
expect(probablize(countByFrom(input))).toEqual(expected); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment