<commit_before>require('../support/test_helper');

var assert = require('../support/assert');
var testClient = require('../support/test_client_old');

describe('torque png renderer', function() {

    var IMAGE_TOLERANCE_PER_MIL = 20;

    var torquePngPointsMapConfig =  {
        version: '1.2.0',
        layers: [
            {
                type: 'torque',
                options: {
                    sql: "SELECT * FROM populated_places_simple_reduced where the_geom" +
                        " && ST_MakeEnvelope(-90, 0, 90, 65)",
                    cartocss: [
                        'Map {',
                        '    buffer-size:0;',
                        '    -torque-frame-count:1;',
                        '    -torque-animation-duration:30;',
                        '    -torque-time-attribute:"cartodb_id";',
                        '    -torque-aggregation-function:"count(cartodb_id)";',
                        '    -torque-resolution:1;',
                        '    -torque-data-aggregation:linear;',
                        '}',
                        '#populated_places_simple_reduced{',
                        '    comp-op: multiply;',
                        '    marker-fill-opacity: 1;',
                        '    marker-line-color: #FFF;',
                        '    marker-line-width: 0;',
                        '    marker-line-opacity: 1;',
                        '    marker-type: rectangle;',
                        '    marker-width: 3;',
                        '    marker-fill: #FFCC00;',
                        '}'
                    ].join(' '),
                    cartocss_version: '2.3.0'
                }
            }
        ]
    };

    var tileRequests = [
        {
            z: 2,
            x: 2,
            y: 1,
            layer: 0,
            format: 'torque.png'
        },
        {
            z: 2,
            x: 1,
            y: 1,
            layer: 0,
            format: 'torque.png'
        }
    ];

    function torquePngFixture(zxy) {
        return './test/fixtures/torque/populated_places_simple_reduced-' + zxy.join('.') + '.png';
    }

    tileRequests.forEach(function(tileRequest) {
        var z = tileRequest.z,
            x = tileRequest.x,
            y = tileRequest.y;
        var zxy = [z, x, y];
        it('tile ' + zxy.join('/') + '.torque.png', function (done) {
            testClient.getTileLayer(torquePngPointsMapConfig, tileRequest, function(err, res) {
                assert.imageEqualsFile(res.body, torquePngFixture(zxy), IMAGE_TOLERANCE_PER_MIL, function(err) {
                    assert.ok(!err);
                    done();
                });
            });
        });
    });


    var mapConfigTorqueOffset = {
        version: '1.3.0',
        layers: [
            {
                type: 'torque',
                options: {
                    sql: "SELECT * FROM populated_places_simple_reduced",
                    cartocss: [
                        'Map {',
                        'buffer-size:0;',
                        '-torque-frame-count:1;',
                        '-torque-animation-duration:30;',
                        '-torque-time-attribute:"cartodb_id";',
                        '-torque-aggregation-function:"count(cartodb_id)";',
                        '-torque-resolution:2;',
                        '-torque-data-aggregation:linear;',
                        '}',
                        '',
                        '#populated_places_simple_reduced{',
                        '  comp-op: lighter;',
                        '  marker-fill-opacity: 0.9;',
                        '  marker-line-color: #2167AB;',
                        '  marker-line-width: 5;',
                        '  marker-line-opacity: 1;',
                        '  marker-type: ellipse;',
                        '  marker-width: 6;',
                        '  marker-fill: #FF9900;',
                        '}',
                        '#populated_places_simple_reduced[frame-offset=1] {',
                        ' marker-width:8;',
                        ' marker-fill-opacity:0.45; ',
                        '}',
                        '#populated_places_simple_reduced[frame-offset=2] {',
                        ' marker-width:10;',
                        ' marker-fill-opacity:0.225; ',
                        '}'
                    ].join(' '),
                    cartocss_version: '2.3.0'
                }
            }
        ]
    };

    it('torque static map with offset', function(done) {
        var w = 600,
            h = 400;

        testClient.getStaticBbox(mapConfigTorqueOffset, -170, -87, 170, 87, w, h, function(err, res, img) {
            if (err) {
                return done(err);
            }

            assert.equal(img.width(), w);
            assert.equal(img.height(), h);

            done();
        });

    });

});<commit_msg>Rewrite torque png test with new test client<commit_after>require('../support/test_helper');

var assert = require('../support/assert');
var TestClient = require('../support/test_client');
var OldTestClient = require('../support/test_client_old');

describe('torque png renderer', function() {

    describe('tiles', function() {

        var IMAGE_TOLERANCE_PER_MIL = 20;

        var torquePngPointsMapConfig =  {
            version: '1.2.0',
            layers: [
                {
                    type: 'torque',
                    options: {
                        sql: "SELECT * FROM populated_places_simple_reduced where the_geom" +
                            " && ST_MakeEnvelope(-90, 0, 90, 65)",
                        cartocss: [
                            'Map {',
                            '    buffer-size:0;',
                            '    -torque-frame-count:1;',
                            '    -torque-animation-duration:30;',
                            '    -torque-time-attribute:"cartodb_id";',
                            '    -torque-aggregation-function:"count(cartodb_id)";',
                            '    -torque-resolution:1;',
                            '    -torque-data-aggregation:linear;',
                            '}',
                            '#populated_places_simple_reduced{',
                            '    comp-op: multiply;',
                            '    marker-fill-opacity: 1;',
                            '    marker-line-color: #FFF;',
                            '    marker-line-width: 0;',
                            '    marker-line-opacity: 1;',
                            '    marker-type: rectangle;',
                            '    marker-width: 3;',
                            '    marker-fill: #FFCC00;',
                            '}'
                        ].join(' '),
                        cartocss_version: '2.3.0'
                    }
                }
            ]
        };

        var testClient;
        before(function() {
            testClient = new TestClient(torquePngPointsMapConfig);
        });

        var tileRequests = [
            {
                z: 2,
                x: 2,
                y: 1
            },
            {
                z: 2,
                x: 1,
                y: 1
            }
        ];

        function torquePngFixture(zxy) {
            return './test/fixtures/torque/populated_places_simple_reduced-' + zxy.join('.') + '.png';
        }

        tileRequests.forEach(function(tileRequest) {
            var z = tileRequest.z,
                x = tileRequest.x,
                y = tileRequest.y;
            var zxy = [z, x, y];
            it('torque png tile ' + zxy.join('/') + '.png', function (done) {
                testClient.getTile(z, x, y, {layer: 0}, function(err, tile) {
                    assert.imageEqualsFile(tile, torquePngFixture(zxy), IMAGE_TOLERANCE_PER_MIL, function(err) {
                        assert.ok(!err);
                        done();
                    });
                });
            });
        });
    });

    describe('static map', function() {
        var mapConfigTorqueOffset = {
            version: '1.3.0',
            layers: [
                {
                    type: 'torque',
                    options: {
                        sql: "SELECT * FROM populated_places_simple_reduced",
                        cartocss: [
                            'Map {',
                            'buffer-size:0;',
                            '-torque-frame-count:1;',
                            '-torque-animation-duration:30;',
                            '-torque-time-attribute:"cartodb_id";',
                            '-torque-aggregation-function:"count(cartodb_id)";',
                            '-torque-resolution:2;',
                            '-torque-data-aggregation:linear;',
                            '}',
                            '',
                            '#populated_places_simple_reduced{',
                            '  comp-op: lighter;',
                            '  marker-fill-opacity: 0.9;',
                            '  marker-line-color: #2167AB;',
                            '  marker-line-width: 5;',
                            '  marker-line-opacity: 1;',
                            '  marker-type: ellipse;',
                            '  marker-width: 6;',
                            '  marker-fill: #FF9900;',
                            '}',
                            '#populated_places_simple_reduced[frame-offset=1] {',
                            ' marker-width:8;',
                            ' marker-fill-opacity:0.45; ',
                            '}',
                            '#populated_places_simple_reduced[frame-offset=2] {',
                            ' marker-width:10;',
                            ' marker-fill-opacity:0.225; ',
                            '}'
                        ].join(' '),
                        cartocss_version: '2.3.0'
                    }
                }
            ]
        };

        it('torque static map with offset', function(done) {
            var w = 600,
                h = 400;

            OldTestClient.getStaticBbox(mapConfigTorqueOffset, -170, -87, 170, 87, w, h, function(err, res, img) {
                if (err) {
                    return done(err);
                }

                assert.equal(img.width(), w);
                assert.equal(img.height(), h);

                done();
            });

        });
    });

});
{'fraction_non_alphanumeric': 0.12607040913415796, 'fraction_numerical': 0.01627021883920076, 'mean_word_length': 0.9293318649045521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7033063', 'n_tokens_mistral': 2977, 'n_tokens_neox': 2697, 'n_words': 406}