-
Notifications
You must be signed in to change notification settings - Fork 12
/
bam_test.clj
85 lines (82 loc) · 2.13 KB
/
bam_test.clj
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
(ns cljam.io.bam-test
"Tests for Processing BAM files."
(:require [clojure.test :refer [deftest are testing]]
[cljam.io.bam.encoder :as encoder]
[cljam.io.bam.decoder :as decoder])
(:import [java.nio ByteBuffer]))
(deftest aux-data-codec-test
(testing "non-array types"
(are [?type ?value]
(= ?value
(as-> (#'encoder/encode-tag-value
(ByteBuffer/allocate 100) ?type ?value) ^ByteBuffer bb
(.position bb 0)
(decoder/parse-tag-single ?type bb) ?type ?value))
\A \@
\A \A
\A \z
\c -128
\c -1
\c 0
\c 127
\C 0
\C 127
\C 128
\C 255
\s -32768
\s -1
\s 0
\s 32767
\S 0
\S 32767
\S 32768
\S 65535
\i -2147483648
\i 0
\i -1
\i 2147483647
\I 0
\I 2147483647
\I 2147483648
\I 4294967295
\f -17.75
\f 0.0
\f 5.75
\f (Float/MAX_VALUE)
\f (Float/MIN_NORMAL)
\f (Float/MIN_VALUE)
\f (Float/NEGATIVE_INFINITY)
\f (Float/POSITIVE_INFINITY)))
(testing "NULL-terminated text"
(are [?type ?value]
(= ?value
(as-> (#'encoder/encode-tag-value
(ByteBuffer/allocate 100) ?type ?value) ^ByteBuffer bb
(.position bb 0)
(decoder/parse-tag-single ?type bb) ?type ?value))
\Z "aaaBBB0011223344@@@+++"
\Z (str "!\"#$%&'()*+,-./0123456789:;<=>?@"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~")))
(testing "array types"
(are [?value]
(= ?value
(as->
(#'encoder/encode-tag-value
(ByteBuffer/allocate 100) \B ?value) ^ByteBuffer bb
(.position bb 0)
(#'decoder/parse-tag-array bb)))
"c,0"
"C,0"
"s,0"
"S,0"
"i,0"
"I,0"
"f,0.0"
"c,-128,0,127"
"C,0,255"
"s,-32768,0,32767"
"S,0,65535"
"i,-2147483648,0,2147483647"
"I,0,4294967295"
"f,-17.25,0.0,5.75"
"f,3.4028235E38,1.17549435E-38,1.4E-45,-Infinity,Infinity")))