-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·64 lines (58 loc) · 4.78 KB
/
test
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
55
56
57
58
59
60
61
62
#!/bin/zsh
assert() {
if [[ "$2" != "$3" ]]; then
echo "Failure: $1\n\tExpected: $3\n\tReceived: $2"
ERR=1
fi
}
a='a\t1'
bc='b\t2\nc\t3'
abc="$a\n$bc"
abcde="$abc\nd\t4\ne\t5"
abc2='a\t2\nb\t4\nc\t6'
abce2='a\t1\nb\t4\nc\t9'
abcn='a\t-1\nb\t-2\nc\t-3'
assert 'abs' "$(./svec abs <(echo "a\t2\nb\t-3"))" "$(echo "a\t2\nb\t3")"
assert 'add one' "$(./svec add <(echo $abc))" "$(echo "$abc")"
assert 'add self' "$(./svec add <(echo $abc) <(echo $abc))" "$(echo "$abc2")"
assert 'add orthogonal dimensions' "$(./svec add <(echo $a) <(echo $bc))" "$(echo "$abc")"
assert 'add n' "$(./svec add <(echo $a) <(echo $bc) <(echo $a) <(echo $bc))" "$(echo "$abc2")"
assert 'analogy' "$(./svec analogy <(echo $a) <(echo $a) <(echo $bc))" "$(echo "$bc")"
assert analogicalinfluence "$(./svec analogicalinfluence <(echo 'b\t-1\nc\t5') <(echo 'b\t-2') <(echo 'a\t10\nb\t-10') <(echo 'a\t11\nb\t-8'))" "$(echo "dimension\t|q-k|-|(q-k)–(w-m)|\t|q-k|-|(q-k)–w|\t|q-k|-|(q-k)+m|\t|q-k|\na\t10\t10\t0\t11\nb\t3\t2\t-1\t6\nc\t-5\t0\t-5\t0")"
assert 'counts' "$(./svec counts <(echo 'c\nc\nc\nb\na\nb'))" "$(echo "$abc")"
assert 'triangular' "$(./svec triangular <(echo "a a\t1\na b\t2\nb a\t2"))" "$(echo "a a\t1\na b\t2")"
assert 'symmetric' "$(./svec symmetric <(echo "a b\t2\na a\t1"))" "$(echo "a a\t1\na b\t2\nb a\t2")"
assert 'symmetric unsorted' "$(./svec symmetric -u <(echo "a b\t2\na a\t1"))" "$(echo "a b\t2\nb a\t2\na a\t1")"
assert 'dimensions' "$(./svec dimensions <(echo "$abc"))" "$(echo 'a\nb\nc')"
assert 'dot' "$(./svec dot <(echo "$abc") <(echo "$abc"))" '14'
assert 'dot orthogonal' "$(./svec dot <(echo "$a") <(echo "$bc"))" ''
assert 'index' "$(./svec index <(echo 'a a\t10\na b\t20'))" "$(echo "a\t1\nb\t2")"
assert 'index -r' "$(./svec index -r <(echo 'a\t1\nb\t2') <(echo 'a a\t10\na b\t20'))" "$(echo "1 1\t10\n1 2\t20")"
assert 'index -d' "$(./svec index -d <(echo 'a\t1\nb\t2') <(echo "1 1\t10\n1 2\t20"))" "$(echo 'a a\t10\na b\t20')"
assert 'minmax min' "$(./svec minmax -m 2 <(echo "$abcde"))" "$(echo "b\t2\nc\t3\nd\t4\ne\t5")"
assert 'minmax max' "$(./svec minmax -x 4 <(echo "$abcde"))" "$(echo "${abc}\nd\t4")"
assert 'minmax min and max' "$(./svec minmax -m 2 -x 4 <(echo "$abcde"))" "$(echo "${bc}\nd\t4")"
assert 'minmax min and max sharp' "$(./svec minmax -M 2 -X 4 <(echo "$abcde"))" "$(echo "c\t3")"
assert 'negate' "$(./svec negate <(echo $abc))" "$(echo "$abcn")"
assert 'neighbors' "$(./svec neighbors <(echo 'a\t3') <(echo 'a a\t2\nb b\t2\nc a\t-2'))" "$(echo "a\t1\nc\t-1")"
assert 'norm' "$(./svec norm <(echo "a\t2\nb\t2\nc\t2\nd\t2"))" '4'
assert 'normalize' "$(./svec normalize <(echo 'a\t4'))" "$(echo "$a")"
assert 'pmi' "$(./svec pmi -g6 -u <(echo 'a a\t1\na b\t2\nb a\t2\nb b\t3') | cut -c -12)" "$(echo "a a\t$(awk 'BEGIN {print log(1*6/3/3)}')\na b\t$(awk 'BEGIN {print log(2*6/3/5)}')\nb a\t$(awk 'BEGIN {print log(2*6/3/5)}')\nb b\t$(awk 'BEGIN {print log(3*6/5/5)}')" | cut -c -12)"
assert 'row' "$(./svec row a <(echo "a a\t1\na b\t2\nb a\t3\nb b\t4"))" "$(echo "a\t1\nb\t2")"
assert 'scale constant' "$(./svec scale 2 <(echo $abc))" "$(echo $abc2)"
assert 'scale arithmetic expressions' "$(./svec scale '(1+1)' <(echo $abc))" "$(echo "$abc2")"
assert 'scale precision' "$(./svec scale -g 3 '.3333333333' <(echo $a))" "$(echo "a\t0.333")"
assert 'serialize vector' "$(./svec serialize <(echo 'a\t1.0\nb\t2.0\nc\t3.0\nd\t4.0') | ./svec deserialize)" "$(echo 'a\t1.0\nb\t2.0\nc\t3.0\nd\t4.0')"
assert 'serialize matrix' "$(./svec serialize <(echo 'a a\t1.0\na b\t2.0\nb b\t3.0\nb c\t4.0') | ./svec deserialize)" "$(echo 'a a\t1.0\na b\t2.0\nb b\t3.0\nb c\t4.0')"
assert 'julia' "$(./svec serialize <(echo $abc) | ./svec julia 'return 2*svec' | ./svec deserialize)" "$(echo 'a\t2.0\nb\t4.0\nc\t6.0')"
assert 'using' "$(./svec serialize <(echo 'a a\t1\na b\t2\nb a\t3\nb b\t4') | ./svec julia -u LinearAlgebra 'return sparse([tr(Array(svec))])' | ./svec deserialize)" "$(echo 'a\t5.0')"
assert 'square' "$(./svec square <(echo $abc))" "$(echo $abce2)"
assert 'subtract' "$(./svec subtract <(echo $abc2) <(echo $abc))" "$(echo "$abc")"
#assert 'subtract from 0' "$(./svec subtract <(echo '') <(echo $abc))" "$(echo "$abcn")"
assert 'subtract multiple' "$(./svec subtract <(echo $abc2) <(echo $abc) <(echo $abc) <(echo $abc))" "$(echo "$abcn")"
assert 'sum' "$(./svec sum <(echo $abc))" '6'
assert 'vecnorm' "$(./svec vecnorm <(echo "a a\t2\na b\t2\na c\t2\na d\t2\nb a\t2\nb b\t2\nb c\t2\nb d\t2"))" "$(echo "a\t4\nb\t4")"
assert 'vecnormalize' "$(./svec vecnormalize <(echo "a a\t2\na b\t2\na c\t2\na d\t2\nb a\t2\nb b\t2\nb c\t2\nb d\t2"))" "$(echo "a a\t0.5\na b\t0.5\na c\t0.5\na d\t0.5\nb a\t0.5\nb b\t0.5\nb c\t0.5\nb d\t0.5")"
assert 'vecsum' "$(./svec vecnorm <(echo "a a\t2\na b\t2\na c\t2\na d\t2\nb a\t2\nb b\t2\nb c\t2\nb d\t2"))" "$(echo "a\t4\nb\t4")"
[[ -z "$ERR" ]] && echo "All Tests Pass"
exit "$ERR"