summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-values/sin-cos-tan-serialize.html
blob: 52a548113a4e2cc2c4ac9811db5b60db0016bf8e (plain)
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
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-values-4/#trig-funcs">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-serialize">
<link rel="author" title="Apple Inc">
<link rel="author" title="Seokho Song" href="seokho@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/numeric-testcommon.js"></script>
<div id=target></div>
<script>
function test_serialization(specified, expected, approx = false) {
    let options = {type: "number"};
    if (approx) {
        options.approx = 1e-6;
    }
    test_math_specified(specified, `calc(${expected})`, options);
    test_math_computed(specified, expected == "NaN" ? "0" : expected, options);
    test_math_used(specified, expected == "NaN" ? "0" : expected, options);
}
//test case, expected, approx
var test_array = [
    ["cos(0)"                                           , "1"],
    ["sin(0)"                                           , "0"],
    ["tan(0)"                                           , "0"],
    ["calc(sin(0) + 0.5)"                               , "0.5"],
    ["calc(sin(0) + cos(0) + tan(0))"                   , "1"],
    ["calc(cos(0) + 0.5)"                               , "1.5"],
    ["calc(tan(0) + 0.5)"                               , "0.5"],
    ["cos(0deg)"                                        , "1"],
    ["sin(0deg)"                                        , "0"],
    ["tan(0deg)"                                        , "0"],
    ["sin(30deg)"                                       , "0.5"],
    ["sin(0.523599)"                                    , "0.5"],
    ["sin(0.523599rad)"                                 , "0.5"],
    ["sin(33.333333grad)"                               , "0.5"],
    ["sin(0.08333333turn)"                              , "0.5"],
    ["cos(60deg)"                                       , "0.5"],
    ["cos(66.66666666grad)"                             , "0.5"],
    ["cos(1.047197551)"                                 , "0.5"],
    ["cos(1.047197551rad)"                              , "0.5"],
    ["cos(0.16666666666turn)"                           , "0.5"],
    ["tan(45deg)"                                       , "1"],
    ["tan(50grad)"                                      , "1"],
    ["tan(0.78539816)"                                  , "1"],
    ["tan(0.78539816rad)"                               , "1"],
    ["tan(0.125turn)"                                   , "1"],
    ["sin(180deg)"                                      , "0", true],
    ["cos(180deg)"                                      , "-1"],
    ["tan(180deg)"                                      , "0", true],
    ["sin(270deg)"                                      , "-1"],
    ["cos(270deg)"                                      , "0", true],
    ["sin(-180deg)"                                     , "0", true],
    ["cos(-180deg)"                                     , "-1"],
    ["tan(-180deg)"                                     , "0", true],
    ["sin(-270deg)"                                     , "1"],
    ["cos(-270deg)"                                     , "0", true],
    ["calc(sin(30deg) + cos(60deg) + tan(45deg))"       , "2"],
    ["calc(sin(infinity))"                              , "NaN"],
    ["calc(cos(infinity))"                              , "NaN"],
    ["calc(tan(infinity))"                              , "NaN"],
    ["calc(sin(-infinity))"                             , "NaN"],
    ["calc(cos(-infinity))"                             , "NaN"],
    ["calc(tan(-infinity))"                             , "NaN"],
    ["calc(sin(NaN))"                                   , "NaN"],
    ["calc(cos(NaN))"                                   , "NaN"],
    ["calc(tan(NaN))"                                   , "NaN"],
];

for (let [test, expected, approx] of test_array) {
    test_serialization(test, expected, approx);
    test_serialization(`calc(${test})`, expected, approx);
}

</script>