-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
177 lines (126 loc) · 3.62 KB
/
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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
var test = require('tape');
var rational = require('./rational');
var tc = require('./index');
test('rational', function (t) {
t.plan(13);
t.equal(new rational.Rational(1,0).den, 0, 'toto');
t.equal(rational.av_cmp_q(
new rational.Rational(12, 135),
new rational.Rational(120, 1350)
), 0);
t.equal(rational.av_cmp_q(
new rational.Rational(12, 34),
new rational.Rational(23, 12)
), -1);
t.equal(rational.av_cmp_q(
new rational.Rational(102, 44),
new rational.Rational(23, 12)
), 1);
t.equal(rational.av_gcd(123, 246), 123);
var a = new rational.Rational(-1, -1);
rational.av_reduce(a, 123442143, 213432, Number.MAX_SAFE_INTEGER);
t.equal(a.num, 41147381);
t.equal(a.den, 71144);
var b = new rational.Rational(123, 435);
var c = new rational.Rational(34, 123);
rational.av_mul_q(b, c);
t.equal(b.num, 34);
t.equal(b.den, 435);
var b1 = new rational.Rational(12, 5);
var c1 = new rational.Rational(2, 3);
rational.av_div_q(b1, c1);
t.equal(b1.num, 18);
t.equal(b1.den, 5);
var b2 = new rational.Rational(12, 5);
var c2 = new rational.Rational(2, 3);
rational.av_add_q(b2, c2);
t.equal(b2.num, 46);
t.equal(b2.den, 15);
});
test('timecode', function (t) {
t.plan(1);
var tc0 = new tc.Timecode(
0,
new tc.Flags(false, true, false),
new rational.Rational(25, 1),
25
);
t.equal(tc0.av_timecode_make_string(120), "00:00:04:20", "tc0.av_timecode_make_string(120) = 00:00:04:20");
});
test('timecode with drop frame (29.97)', function (t) {
t.plan(1);
var tc0 = new tc.Timecode(
0,
new tc.Flags(true, true, false),
new rational.Rational(30000, 1001),
30
);
t.equal(tc0.av_timecode_make_string(120), "00:00:04;00", "tc0.av_timecode_make_string(120) = 00:00:04;00");
});
test('timecode with drop frame (59.94)', function (t) {
t.plan(1);
var tc0 = new tc.Timecode(
0,
new tc.Flags(true, true, false),
new rational.Rational(60000, 1001),
60
);
t.equal(tc0.av_timecode_make_string(120), "00:00:02;00", "tc0.av_timecode_make_string(120) = 00:00:02;00");
});
test('parse timecode from string @25', function (t) {
t.plan(1);
var tc0 = tc.parse(
new rational.Rational(25, 1),
"00:12:24:23"
);
t.equal(tc0.start, 18623, "tc.parse");
});
test('parse timecode from string @29.97', function (t) {
t.plan(1);
var tc0 = tc.parse(
new rational.Rational(30000, 1001),
"00:12:24;23"
);
t.equal(tc0.start, 22321, "tc.parse");
});
test('throw invalid timecode string', function (t) {
t.plan(4);
t.throws(function () {
tc.parse(
new rational.Rational(30000, 1001),
""
)
}, 'Throws `Invalid timecode string`');
t.throws(function () {
tc.parse(
new rational.Rational(30000, 1001),
"plopplop"
)
}, 'Throws `Invalid timecode string`');
t.throws(function () {
tc.parse(
new rational.Rational(30000, 1001),
"dsadsa32100:12:24;23"
)
}, 'Throws `Invalid timecode string`');
t.throws(function () {
tc.parse(
new rational.Rational(30000, 1001),
"dsadsa32100:12:24;23gokgokrekgoke"
)
}, 'Throws `Invalid timecode string`');
});
test('add 1292.042 seconds to 00:59:59:00@24000/1001 = 01:21:29:17', function (t) {
t.plan(1);
// duration in seconds
var duration = 1292.042;
// images range
var images = Math.floor(1292.042 * (24000/1001));
// frame number
var imageNumber = images - 1;
var tc0 = tc.parse(
new rational.Rational(24000, 1001),
"00:59:59:00"
);
t.equal(tc0.av_timecode_make_string(imageNumber), "01:21:29:17", "tc.av_timecode_make_string");
});