<commit_before>var clipper = require('../');

Promise.promisifyAll(clipper);

function wrap(args) {
    return function() {
        clipper.simplify.apply(null, args);
    };
}

describe('clipper.simplify()', function() {
    it('should throw an error if no arguments are provided', function() {
        expect(wrap([])).to.throw(TypeError, 'Wrong type for argument 1: expected array');
    });

    it('should throw an error if the first argument is the wrong type', function() {
        var args1 = [true];
        var args2 = [0];
        var args3 = ['str'];
        var args4 = [null];
        var args5 = [{
            prop: 'one'
        }];
        expect(wrap(args1)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args2)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args3)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args4)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args5)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
    });

    // From Delphi website:
    // - http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/SimplifyPolygon.htm
    // - Accessed 6/27/2015
    // - Star example
    it('should correctly simplify a polygon with self-intersections (star)', function() {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        expect(clipper.simplify(poly, 1.0, clipper.PolyFillType.POSITIVE)).to.eql([
            [
                [
                    527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                    360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                ]
            ],
            []
        ]);
    });

    it('should correctly scale the vertices', function() {
        var poly = [0.480, 0.120, 0.600, 0.515, 0.285, 0.275, 0.675, 0.275, 0.360, 0.515];
        expect(clipper.simplify(poly, 1000, clipper.PolyFillType.POSITIVE)).to.eql([
            [
                [
                    0.527, 0.275, 0.675, 0.275, 0.555, 0.367, 0.600, 0.515, 0.480, 0.424,
                    0.360, 0.515, 0.405, 0.367, 0.285, 0.275, 0.433, 0.275, 0.480, 0.120
                ]
            ],
            []
        ]);
    });

    it('should correctly simplify a polygon with a callback', function(done) {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        clipper.simplify(poly, 1.0, clipper.PolyFillType.POSITIVE, function(err, result) {
            expect(result).to.eql([
                [
                    [
                        527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                        360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                    ]
                ],
                []
            ]);
            done();
        });
    });

    it('should correctly simplify a polygon using promises', function() {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        return clipper.simplifyAsync(poly, 1.0, clipper.PolyFillType.POSITIVE).spread(function(outer, hole) {
            expect(outer).to.eql([
                [
                    527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                    360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                ]
            ]);
            expect(hole).to.eql([]);
        });
    });
<commit_msg>Adding test<commit_after>var clipper = require('../');

Promise.promisifyAll(clipper);

function wrap(args) {
    return function() {
        clipper.simplify.apply(null, args);
    };
}

describe('clipper.simplify()', function() {
    it('should throw an error if no arguments are provided', function() {
        expect(wrap([])).to.throw(TypeError, 'Wrong type for argument 1: expected array');
    });

    it('should throw an error if the first argument is the wrong type', function() {
        var args1 = [true];
        var args2 = [0];
        var args3 = ['str'];
        var args4 = [null];
        var args5 = [{
            prop: 'one'
        }];
        expect(wrap(args1)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args2)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args3)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args4)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
        expect(wrap(args5)).to.throw(TypeError, 'Wrong type for argument 1: expected array');
    });

    // From Delphi website:
    // - http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/SimplifyPolygon.htm
    // - Accessed 6/27/2015
    // - Star example
    it('should correctly simplify a polygon with self-intersections (star)', function() {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        expect(clipper.simplify(poly, 1.0, clipper.PolyFillType.NONZERO)).to.eql([
            [
                [
                    527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                    360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                ]
            ],
            []
        ]);
    });

    // From Delphi website:
    // - http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/SimplifyPolygon.htm
    // - Accessed 6/27/2015
    // - First non-contiguous example (simplified)
    it('should correctly simplify a polygon with non-contiguous duplicate vertices', function() {
        var poly = [0, 0, 0, 10, 10, 10, 10, 20, 20, 20, 20, 10, 10, 10, 10, 0];
        expect(clipper.simplify(poly, 1.0, clipper.PolyFillType.NONZERO)).to.eql([
            [
                [
                    20, 10, 20, 20, 10, 20, 10, 10
                ],
                [
                    0, 10, 0, 0, 10, 0, 10, 10
                ]
            ],
            []
        ]);
    });

    // From Delphi website:
    // - http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/SimplifyPolygon.htm
    // - Accessed 6/27/2015
    // - Second non-contiguous example (simplified)
    it('should correctly simplify a polygon with non-contiguous duplicate vertices with hole', function() {
        var poly = [0, 10, 10, 20, 5, 10, 15, 10, 10, 20, 20, 10, 10, 0];
        expect(clipper.simplify(poly, 1.0, clipper.PolyFillType.NONZERO)).to.eql([
            [
                [
                    0, 10, 10, 0, 20, 10, 10, 20
                ]
            ],
            [
                [
                    15, 10, 5, 10, 10, 20
                ]
            ]
        ]);
    });

    it('should correctly scale the vertices', function() {
        var poly = [0.480, 0.120, 0.600, 0.515, 0.285, 0.275, 0.675, 0.275, 0.360, 0.515];
        expect(clipper.simplify(poly, 1000, clipper.PolyFillType.NONZERO)).to.eql([
            [
                [
                    0.527, 0.275, 0.675, 0.275, 0.555, 0.367, 0.600, 0.515, 0.480, 0.424,
                    0.360, 0.515, 0.405, 0.367, 0.285, 0.275, 0.433, 0.275, 0.480, 0.120
                ]
            ],
            []
        ]);
    });

    it('should correctly simplify a polygon with a callback', function(done) {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        clipper.simplify(poly, 1.0, clipper.PolyFillType.NONZERO, function(err, result) {
            expect(result).to.eql([
                [
                    [
                        527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                        360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                    ]
                ],
                []
            ]);
            done();
        });
    });

    it('should correctly simplify a polygon using promises', function() {
        var poly = [480, 120, 600, 515, 285, 275, 675, 275, 360, 515];
        return clipper.simplifyAsync(poly, 1.0, clipper.PolyFillType.NONZERO).spread(function(outer, hole) {
            expect(outer).to.eql([
                [
                    527, 275, 675, 275, 555, 367, 600, 515, 480, 424,
                    360, 515, 405, 367, 285, 275, 433, 275, 480, 120
                ]
            ]);
            expect(hole).to.eql([]);
        });
    });

{'fraction_non_alphanumeric': 0.1474151373395706, 'fraction_numerical': 0.1165887009715725, 'mean_word_length': 1.7027552674230146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3476026', 'n_tokens_mistral': 3494, 'n_tokens_neox': 2546, 'n_words': 687}