<commit_before>var PostgresDatasource = require('../../../../lib/cartodb/backends/turbo-carto-postgres-datasource');
var PSQL = require('cartodb-psql');
var _ = require('underscore');
var assert = require('assert');

describe('turbo-carto-postgres-datasource', function() {

    beforeEach(function () {
        const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
        const dbuser = _.template(global.environment.postgres_auth_user, { user_id: 1 })
        const pass = _.template(global.environment.postgres_auth_pass, { user_id: 1 })
        const psql = new PSQL({
            user: 'postgres',
            dbname: dbname,
            host: global.environment.postgres.host,
            port: global.environment.postgres.port
        });
        const sql =  [
            'SELECT',
            '  null::geometry the_geom_webmercator,',
            '  CASE',
            '    WHEN x % 4 = 0 THEN \'infinity\'::float',
            '    WHEN x % 4 = 1 THEN \'-infinity\'::float',
            '    WHEN x % 4 = 2 THEN \'NaN\'::float',
            '    ELSE x',
            '  END AS values',
            'FROM generate_series(1, 1000) x'
        ].join('\n')
        this.datasource = new PostgresDatasource(psql, sql);
    });

    it('should ignore NaNs and Infinities when computing ramps', function(done) {
       column = 'values';
       buckets = 4;
       method = 'equal';
       this.datasource.getRamp(column, buckets, method, function(err, result) {
           expected_result = {
               ramp: [ 252, 501, 750, 999 ],
               stats: { min_val: 3, max_val: 999, avg_val: 501 },
               strategy: undefined
            };
           assert.deepEqual(result, expected_result);
           done();
       });
    });
});
<commit_msg>Syntax fixes<commit_after>var PostgresDatasource = require('../../../../lib/cartodb/backends/turbo-carto-postgres-datasource');
var PSQL = require('cartodb-psql');
var _ = require('underscore');
var assert = require('assert');

describe('turbo-carto-postgres-datasource', function() {

    beforeEach(function () {
        const dbname = _.template(global.environment.postgres_auth_user, { user_id: 1 }) + '_db';
        const psql = new PSQL({
            user: 'postgres',
            dbname: dbname,
            host: global.environment.postgres.host,
            port: global.environment.postgres.port
        });
        const sql =  [
            'SELECT',
            '  null::geometry the_geom_webmercator,',
            '  CASE',
            '    WHEN x % 4 = 0 THEN \'infinity\'::float',
            '    WHEN x % 4 = 1 THEN \'-infinity\'::float',
            '    WHEN x % 4 = 2 THEN \'NaN\'::float',
            '    ELSE x',
            '  END AS values',
            'FROM generate_series(1, 1000) x'
        ].join('\n');
        this.datasource = new PostgresDatasource(psql, sql);
    });

    it('should ignore NaNs and Infinities when computing ramps', function(done) {
       var column = 'values';
       var buckets = 4;
       var method = 'equal';
       this.datasource.getRamp(column, buckets, method, function(err, result) {
           var expected_result = {
               ramp: [ 252, 501, 750, 999 ],
               stats: { min_val: 3, max_val: 999, avg_val: 501 },
               strategy: undefined
            };
           assert.deepEqual(result, expected_result);
           done();
       });
    });
});

{'fraction_non_alphanumeric': 0.1424013921113689, 'fraction_numerical': 0.0191415313225058, 'mean_word_length': 1.9529109589041096, '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': '7058224', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1015, 'n_words': 231}