|
| 1 | +// wink-nlp |
| 2 | +// |
| 3 | +// Copyright (C) GRAYPE Systems Private Limited |
| 4 | +// |
| 5 | +// This file is part of “wink-nlp”. |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any |
| 8 | +// person obtaining a copy of this software and |
| 9 | +// associated documentation files (the "Software"), to |
| 10 | +// deal in the Software without restriction, including |
| 11 | +// without limitation the rights to use, copy, modify, |
| 12 | +// merge, publish, distribute, sublicense, and/or sell |
| 13 | +// copies of the Software, and to permit persons to |
| 14 | +// whom the Software is furnished to do so, subject to |
| 15 | +// the following conditions: |
| 16 | +// |
| 17 | +// The above copyright notice and this permission notice |
| 18 | +// shall be included in all copies or substantial |
| 19 | +// portions of the Software. |
| 20 | +// |
| 21 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF |
| 22 | +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 23 | +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 24 | +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 25 | +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 26 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 27 | +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 28 | +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 29 | +// DEALINGS IN THE SOFTWARE. |
| 30 | + |
| 31 | +// |
| 32 | + |
| 33 | +var chai = require( 'chai' ); |
| 34 | +var mocha = require( 'mocha' ); |
| 35 | +var ima = require( '../src/identify-marked-area.js' ); |
| 36 | + |
| 37 | +var expect = chai.expect; |
| 38 | +var describe = mocha.describe; |
| 39 | +var it = mocha.it; |
| 40 | + |
| 41 | +describe( 'Identify marked area', function () { |
| 42 | + // Assume the entity length is 6 tokens and the area has |
| 43 | + // to be decided by different values of `mark`. Note `mark`'s |
| 44 | + // first & last indexes are 0 based when counting forward; |
| 45 | + // and when counting backwards, `-1` refers to last and `-2` |
| 46 | + // to last but one and so on. |
| 47 | + const length = 6; |
| 48 | + |
| 49 | + it( 'Left edge to right edge should return the entire area', function () { |
| 50 | + // Counting forward. |
| 51 | + // Note: the values in expect's comments are without the `lastIndex` manoeuvre to |
| 52 | + // bring clarity in the test cases. Refer to the source file under test for details. |
| 53 | + expect( ima( [ 0, 5 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 54 | + // Counting backwards corresponding to the above. |
| 55 | + expect( ima( [ -6, -1 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 56 | + // Mix of backwards & forward. |
| 57 | + expect( ima( [ -6, 5 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 58 | + expect( ima( [ 0, -1 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 59 | + } ); |
| 60 | + |
| 61 | + it( 'Single values at left edge, middle(2nd) & right edge should yield [0, 0], [2, 2], & [5, 5]', function () { |
| 62 | + // Counting forward. |
| 63 | + expect( ima( [ 0, 0 ], length ) ).deep.equals( [ 0, 5 ] ); // [ 0, 0 ] |
| 64 | + expect( ima( [ 2, 2 ], length ) ).deep.equals( [ 2, 3 ] ); // [ 2, 2 ] |
| 65 | + expect( ima( [ 5, 5 ], length ) ).deep.equals( [ 5, 0 ] ); // [ 5, 5 ] |
| 66 | + // Counting backwards corresponding to the above. |
| 67 | + expect( ima( [ -6, -6 ], length ) ).deep.equals( [ 0, 5 ] ); // [ 0, 0 ] |
| 68 | + expect( ima( [ -4, -4 ], length ) ).deep.equals( [ 2, 3 ] ); // [ 2, 2 ] |
| 69 | + expect( ima( [ -1, -1 ], length ) ).deep.equals( [ 5, 0 ] ); // [ 5, 5 ] |
| 70 | + // Mix of backwards & forward. |
| 71 | + expect( ima( [ -6, 0 ], length ) ).deep.equals( [ 0, 5 ] ); // [ 0, 0 ] |
| 72 | + expect( ima( [ -4, 2 ], length ) ).deep.equals( [ 2, 3 ] ); // [ 2, 2 ] |
| 73 | + expect( ima( [ 2, -4 ], length ) ).deep.equals( [ 2, 3 ] ); // [ 2, 2 ] |
| 74 | + expect( ima( [ 5, -1 ], length ) ).deep.equals( [ 5, 0 ] ); // [ 5, 5 ] |
| 75 | + expect( ima( [ -1, 5 ], length ) ).deep.equals( [ 5, 0 ] ); // [ 5, 5 ] |
| 76 | + } ); |
| 77 | + |
| 78 | + it( 'Out of bound values should yield the entire area i.e. [0, 5]', function () { |
| 79 | + // Counting forward beyond limits |
| 80 | + expect( ima( [ 20, 500 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 81 | + // Going backwards beyond limits |
| 82 | + expect( ima( [ -10, 0 ], length ) ).deep.equals( [ 0, 5 ] ); // [ 0, 0 ] |
| 83 | + expect( ima( [ -10, -1 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 84 | + expect( ima( [ -10, -7 ], length ) ).deep.equals( [ 0, 0 ] ); // [ 0, 5 ] |
| 85 | + } ); |
| 86 | +} ); |
0 commit comments