sin-cos-tan-serialize.html (4110B)
1 <!DOCTYPE html> 2 <link rel="help" href="https://drafts.csswg.org/css-values-4/#trig-funcs"> 3 <link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers"> 4 <link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-serialize"> 5 <link rel="author" title="Apple Inc"> 6 <link rel="author" title="Seokho Song" href="seokho@chromium.org"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="../support/numeric-testcommon.js"></script> 10 <div id=target></div> 11 <script> 12 function test_serialization(specified, expected, approx = false) { 13 let options = {type: "number"}; 14 if (approx) { 15 options.approx = 1e-6; 16 } 17 test_math_specified(specified, `calc(${expected})`, options); 18 test_math_computed(specified, expected == "NaN" ? "0" : expected, options); 19 test_math_used(specified, expected == "NaN" ? "0" : expected, options); 20 } 21 //test case, expected, approx 22 var test_array = [ 23 ["cos(0)" , "1"], 24 ["sin(0)" , "0"], 25 ["tan(0)" , "0"], 26 ["calc(sin(0) + 0.5)" , "0.5"], 27 ["calc(sin(0) + cos(0) + tan(0))" , "1"], 28 ["calc(cos(0) + 0.5)" , "1.5"], 29 ["calc(tan(0) + 0.5)" , "0.5"], 30 ["cos(0deg)" , "1"], 31 ["sin(0deg)" , "0"], 32 ["tan(0deg)" , "0"], 33 ["sin(30deg)" , "0.5"], 34 ["sin(0.523599)" , "0.5"], 35 ["sin(0.523599rad)" , "0.5"], 36 ["sin(33.333333grad)" , "0.5"], 37 ["sin(0.08333333turn)" , "0.5"], 38 ["cos(60deg)" , "0.5"], 39 ["cos(66.66666666grad)" , "0.5"], 40 ["cos(1.047197551)" , "0.5"], 41 ["cos(1.047197551rad)" , "0.5"], 42 ["cos(0.16666666666turn)" , "0.5"], 43 ["tan(45deg)" , "1"], 44 ["tan(50grad)" , "1"], 45 ["tan(0.78539816)" , "1"], 46 ["tan(0.78539816rad)" , "1"], 47 ["tan(0.125turn)" , "1"], 48 ["sin(180deg)" , "0", true], 49 ["cos(180deg)" , "-1"], 50 ["tan(180deg)" , "0", true], 51 ["sin(270deg)" , "-1"], 52 ["cos(270deg)" , "0", true], 53 ["sin(-180deg)" , "0", true], 54 ["cos(-180deg)" , "-1"], 55 ["tan(-180deg)" , "0", true], 56 ["sin(-270deg)" , "1"], 57 ["cos(-270deg)" , "0", true], 58 ["calc(sin(30deg) + cos(60deg) + tan(45deg))" , "2"], 59 ["calc(sin(infinity))" , "NaN"], 60 ["calc(cos(infinity))" , "NaN"], 61 ["calc(tan(infinity))" , "NaN"], 62 ["calc(sin(-infinity))" , "NaN"], 63 ["calc(cos(-infinity))" , "NaN"], 64 ["calc(tan(-infinity))" , "NaN"], 65 ["calc(sin(NaN))" , "NaN"], 66 ["calc(cos(NaN))" , "NaN"], 67 ["calc(tan(NaN))" , "NaN"], 68 ]; 69 70 for (let [test, expected, approx] of test_array) { 71 test_serialization(test, expected, approx); 72 test_serialization(`calc(${test})`, expected, approx); 73 } 74 75 </script>