<commit_before><!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            // http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
            window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};
        </script>
        <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="tinycolor.js"></script>
        <script type="text/javascript" src="../imgtocss.js"></script>
        <script type="text/javascript" src="qunit.js"></script>
        <link rel="stylesheet" href="qunit.css" type="text/css">
<script type="text/javascript">
    function random() {
        var f = function() {
            return Math.floor(Math.random() * 255);
        }

        return tinycolor({
            r: f(),
            g: f(),
            b: f(),
            a: Math.round( (f() / 255) * 100 ) / 100
        }).toString();
    }

    var gradTests = {
        singleStop: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": random()
            }
        },
        singleVertical: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": random(),
                "1": random()
            }
        },
        multiVertical: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": random(),
                "0.25": random(),
                "0.50": random(),
                "0.75": random(),
                "1": random()
            }
        },
        singleHorizontal: {
            start: "left",
            param: [0, 0, 1, 0],
            stops: {
                "0": random(),
                "1": random()
            }
        },
        multiHorizontal: {
            start: "left",
            param: [1, 0, 0, 0 ],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.25": "rgb(255, 0, 232)",
                "0.50": "rgb(59, 42, 108)",
                "0.75": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        }/*,
        singleDiagLtr: {
            start: "top_left",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        multiDiagLtr: {
            start: "top_left",
            param: [1, 1, 0, 0],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.21717171717171718": "rgb(255, 0, 232)",
                "0.4696969696969697": "rgb(59, 42, 108)",
                "0.7474747474747475": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        singleDiagRtl: {
            start: "top_right",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        multiDiagRtl: {
            start: "top_right",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.21717171717171718": "rgb(255, 0, 232)",
                "0.4696969696969697": "rgb(59, 42, 108)",
                "0.7474747474747475": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        }*/
    };

    $(function() {
        QUnit.init();

        var key, canvas, context, grad, gradient, idx, calcgrad;
        for (key in gradTests) {
            if (gradTests.hasOwnProperty(key)) {
                var width = 500;
                var height = 500;

                grad = gradTests[key];
                canvas = document.createElement('canvas');
                context = canvas.getContext('2d')
                canvas.width = width;
                canvas.height = height;
                var param = [grad.param[0] * width, grad.param[1] * height, grad.param[2] * width, grad.param[3] * height];
                gradient = context.createLinearGradient.apply(context, param);

                for (idx in grad.stops) {
                    if (grad.stops.hasOwnProperty(idx)) {
                        gradient.addColorStop(parseFloat(idx), grad.stops[idx]);
                    }
                }
                context.fillStyle = gradient;
                context.fillRect(0, 0, width, height);
                testGrad(key, grad, canvas);
                $("body").append(canvas);

            }
        }

        function testGrad(name, grad, canvas) {
            var calcgrad = GradientCalc.findGradFromCanvas(canvas);
            test(name, function() {

                var calcstops = {};
                calcgrad.stops.forEach(function(s) {   
                    var found = false;
                    for (var i in grad.stops) {
                        var diff = Math.abs(s.idx - i);
                        log(i);
                        if (diff <= 0.050) {
                            var a = tinycolor(s.color);
                            var b = tinycolor(grad.stops[i]);
                            ok(GradientCalc.colorsEqual(a, b), "Calc:" +  s.idx + " " + a.toRgbString() + "  Exp: " +i + " " + b.toRgbString());
                            found = true;
                            break;
                        }
                    }
                    
                    ok(found, "Looking for a stop at " + s.idx);                    
                });
            });
        }
    });
</script>

</head>
    <body>
        <h1 id="qunit-header">QUnit example</h1>
        <h2 id="qunit-banner"></h2>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests">
    </body>
</html>


<commit_msg>convert to using staticly defined colors for tests -- makes it easier to test specific cases.<commit_after><!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            // http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
            window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};
        </script>
        <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
        <script type="text/javascript" src="tinycolor.js"></script>
        <script type="text/javascript" src="../imgtocss.js"></script>
        <script type="text/javascript" src="qunit.js"></script>
        <link rel="stylesheet" href="qunit.css" type="text/css">
<script type="text/javascript">
    function random() {
        var f = function() {
            return Math.floor(Math.random() * 255);
        }

        return tinycolor({
            r: f(),
            g: f(),
            b: f(),
            a: Math.max(Math.round( (f() / 255) * 100 ) / 100, .1)
        }).toString();
    }

    var gradTests = {
        singleStop: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": random()
            }
        },
        singleVertical: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgba(255, 255, 255, 1)",
                "1": "rgb(0, 0, 0)"
            }
        },
        multiVertical: {
            start: "top",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgba(203, 65, 246, 0.88)",
                "0.25": "rgba(255, 255, 255, 0.1)",
                "0.50": "rgba(243, 81, 53, 0.25)",
                "0.75": "rgba(203, 65, 246, 1)",
                "1": "rgba(82, 232, 212, 0.1)"
            }
        },
        singleHorizontal: {
            start: "left",
            param: [0, 0, 1, 0],
            stops: {
                "0": "rgba(1, 53, 112, 0.87)",
                "1": "rgba(82, 232, 212, 0.15)"
            }
        },
        multiHorizontal: {
            start: "left",
            param: [0, 0, 1, 0 ],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.25": "rgb(255, 0, 232)",
                "0.50": "rgb(59, 42, 108)",
                "0.75": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        }/*,
        singleDiagLtr: {
            start: "top_left",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        multiDiagLtr: {
            start: "top_left",
            param: [1, 1, 0, 0],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.21717171717171718": "rgb(255, 0, 232)",
                "0.4696969696969697": "rgb(59, 42, 108)",
                "0.7474747474747475": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        singleDiagRtl: {
            start: "top_right",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        },
        multiDiagRtl: {
            start: "top_right",
            param: [0, 0, 0, 1],
            stops: {
                "0": "rgb(0, 0, 0)",
                "0.21717171717171718": "rgb(255, 0, 232)",
                "0.4696969696969697": "rgb(59, 42, 108)",
                "0.7474747474747475": "rgb(68, 0, 0)",
                "1": "rgb(255, 255, 255)"
            }
        }*/
    };

    $(function() {
        QUnit.init();

        var key, canvas, context, grad, gradient, idx, calcgrad;
        for (key in gradTests) {
            if (gradTests.hasOwnProperty(key)) {
                var width = 500;
                var height = 500;

                grad = gradTests[key];
                canvas = document.createElement('canvas');
                context = canvas.getContext('2d')
                canvas.width = width;
                canvas.height = height;
                var param = [grad.param[0] * width, grad.param[1] * height, grad.param[2] * width, grad.param[3] * height];
                gradient = context.createLinearGradient.apply(context, param);

                for (idx in grad.stops) {
                    if (grad.stops.hasOwnProperty(idx)) {
                        gradient.addColorStop(parseFloat(idx), grad.stops[idx]);
                    }
                }
                context.fillStyle = gradient;
                context.fillRect(0, 0, width, height);
                testGrad(key, grad, canvas);
                $("body").append(canvas);

            }
        }

        function testGrad(name, grad, canvas) {
            var calcgrad = GradientCalc.findGradFromCanvas(canvas);
            test(name, function() {
                expect(grad.stops.length);
                calcgrad.stops.forEach(function(s) {   
                    var found = false;
                    for (var i in grad.stops) {
                        var diff = Math.abs(s.idx - i);
                        if (diff <= 0.050) {
                            var a = tinycolor(s.color);
                            var b = tinycolor(grad.stops[i]);
                            ok(GradientCalc.colorsEqual(a.toRgb(), b.toRgb()), "Calc:" +  s.idx + " " + a.toRgbString() + "  Exp: " +i + " " + b.toRgbString());
                            found = true;
                            break;
                        }
                    }
                });
            });
        }
    });
</script>

</head>
    <body>
        <h1 id="qunit-header">QUnit example</h1>
        <h2 id="qunit-banner"></h2>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests">
    </body>
</html>



{'fraction_non_alphanumeric': 0.15988347185331162, 'fraction_numerical': 0.06400479821780482, 'mean_word_length': 1.1833146277590723, 'pattern_counts': {'":': 58, '<': 59, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6153527', 'n_tokens_mistral': 4107, 'n_tokens_neox': 3506, 'n_words': 748}