deno.land / x / simplestatistic@v7.7.1 / test / ckmeans.test.js

ckmeans.test.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint no-shadow: 0 */
const test = require("tap").test;const cK = require("../").ckmeans;
test("C k-means", function (t) { t.ok(cK, "exports fn");
t.throws(function () { cK([], 10); }, "Cannot generate more values than input");
t.same(cK([1], 1), [[1]], "single-value case");
t.same(cK([1, 1, 1, 1], 1), [[1, 1, 1, 1]], "same-value case");
const exampleInput = [-1, 2, -1, 2, 4, 5, 6, -1, 2, -1]; const example = cK(exampleInput, 3);
t.same(example, [ [-1, -1, -1, -1], [2, 2, 2], [4, 5, 6] ]); t.same(cK([1, 2, 3], 3), [[1], [2], [3]]);
t.same(cK([0, 3, 4], 2), [[0], [3, 4]]); t.same(cK([-3, 0, 4], 2), [[-3, 0], [4]]);
t.same(cK([1, 2, 2, 3], 3), [[1], [2, 2], [3]]); t.same(cK([1, 2, 2, 3, 3], 3), [[1], [2, 2], [3, 3]]); t.same(cK([1, 2, 3, 2, 3], 3), [[1], [2, 2], [3, 3]]); t.same(cK([3, 2, 3, 2, 1], 3), [[1], [2, 2], [3, 3]]); t.same(cK([3, 2, 3, 5, 2, 1], 3), [[1, 2, 2], [3, 3], [5]]);
t.same(cK([0, 1, 2, 100, 101, 103], 2), [ [0, 1, 2], [100, 101, 103] ]); t.same(cK([0, 1, 2, 50, 100, 101, 103], 3), [ [0, 1, 2], [50], [100, 101, 103] ]);
// Covers a floating point imprecision edge case t.same(cK([64.64249127327881, 64.64249127328245, 57.79216426169771], 2), [ [57.79216426169771], [64.64249127327881, 64.64249127328245] ]);
t.end();});
simplestatistic

Version Info

Tagged at
2 years ago