|  | 
|  | 1 | +import splitTestData from '../src/splitTestData'; | 
|  | 2 | + | 
|  | 3 | +const tables = { | 
|  | 4 | +  features: [ | 
|  | 5 | +    [1, 2], | 
|  | 6 | +    [3, 4], | 
|  | 7 | +    [5, 6], | 
|  | 8 | +    [7, 8], | 
|  | 9 | +  ], | 
|  | 10 | +  labels: [[9], [10], [11], [12]], | 
|  | 11 | +}; | 
|  | 12 | + | 
|  | 13 | +test('Default splitting, splits in half', () => { | 
|  | 14 | +  const { features, labels, testFeatures, testLabels } = splitTestData( | 
|  | 15 | +    tables.features, | 
|  | 16 | +    tables.labels, | 
|  | 17 | +    true | 
|  | 18 | +  ); | 
|  | 19 | +  expect(features).toMatchObject([ | 
|  | 20 | +    [1, 2], | 
|  | 21 | +    [3, 4], | 
|  | 22 | +  ]); | 
|  | 23 | +  expect(labels).toMatchObject([[9], [10]]); | 
|  | 24 | +  expect(testFeatures).toMatchObject([ | 
|  | 25 | +    [5, 6], | 
|  | 26 | +    [7, 8], | 
|  | 27 | +  ]); | 
|  | 28 | +  expect(testLabels).toMatchObject([[11], [12]]); | 
|  | 29 | +}); | 
|  | 30 | + | 
|  | 31 | +test('Splitting a fixed amount works', () => { | 
|  | 32 | +  const { features, labels, testFeatures, testLabels } = splitTestData( | 
|  | 33 | +    tables.features, | 
|  | 34 | +    tables.labels, | 
|  | 35 | +    1 | 
|  | 36 | +  ); | 
|  | 37 | +  expect(features).toMatchObject([ | 
|  | 38 | +    [1, 2], | 
|  | 39 | +    [3, 4], | 
|  | 40 | +    [5, 6], | 
|  | 41 | +  ]); | 
|  | 42 | +  expect(labels).toMatchObject([[9], [10], [11]]); | 
|  | 43 | +  expect(testFeatures).toMatchObject([[7, 8]]); | 
|  | 44 | +  expect(testLabels).toMatchObject([[12]]); | 
|  | 45 | +}); | 
|  | 46 | + | 
|  | 47 | +test('Splitting more than row length splits all rows into test data', () => { | 
|  | 48 | +  const { features, labels, testFeatures, testLabels } = splitTestData( | 
|  | 49 | +    tables.features, | 
|  | 50 | +    tables.labels, | 
|  | 51 | +    tables.features.length * 2 | 
|  | 52 | +  ); | 
|  | 53 | +  expect(features).toMatchObject([]); | 
|  | 54 | +  expect(labels).toMatchObject([]); | 
|  | 55 | +  expect(testFeatures).toMatchObject([ | 
|  | 56 | +    [1, 2], | 
|  | 57 | +    [3, 4], | 
|  | 58 | +    [5, 6], | 
|  | 59 | +    [7, 8], | 
|  | 60 | +  ]); | 
|  | 61 | +  expect(testLabels).toMatchObject([[9], [10], [11], [12]]); | 
|  | 62 | +}); | 
|  | 63 | + | 
|  | 64 | +test('Splitting less than or equal to 0 places all rows into normal data', () => { | 
|  | 65 | +  [0, -1].forEach((splitLength) => { | 
|  | 66 | +    const { features, labels, testFeatures, testLabels } = splitTestData( | 
|  | 67 | +      tables.features, | 
|  | 68 | +      tables.labels, | 
|  | 69 | +      splitLength | 
|  | 70 | +    ); | 
|  | 71 | +    expect(features).toMatchObject([ | 
|  | 72 | +      [1, 2], | 
|  | 73 | +      [3, 4], | 
|  | 74 | +      [5, 6], | 
|  | 75 | +      [7, 8], | 
|  | 76 | +    ]); | 
|  | 77 | +    expect(labels).toMatchObject([[9], [10], [11], [12]]); | 
|  | 78 | +    expect(testFeatures).toMatchObject([]); | 
|  | 79 | +    expect(testLabels).toMatchObject([]); | 
|  | 80 | +  }); | 
|  | 81 | +}); | 
0 commit comments