__tests__/splitFullTrackIntoTrackSections.ts

mail@pastecode.io avatar
unknown
plain_text
6 months ago
11 kB
2
Indexable
Never
import {splitFullTrackIntoTrackSections} from '@Utils/splitFullTrackIntoTrackSections';

const tracks1 = [
  {data: 1, station_1: 'A', station_2: 'B', station_name: 'A'},
  {data: 2, station_1: 'A', station_2: 'B', station_name: null},
  {data: 3, station_1: 'A', station_2: 'B', station_name: null},
  {data: 4, station_1: 'B', station_2: 'C', station_name: 'B'},
  {data: 5, station_1: 'B', station_2: 'C', station_name: null},
  {data: 6, station_1: 'C', station_2: 'D', station_name: 'C'},
  {data: 7, station_1: 'D', station_2: 'E', station_name: 'D'},
  {data: 8, station_1: 'D', station_2: 'E', station_name: null},
  {data: 9, station_1: 'E', station_2: 'F', station_name: 'E'},
  {data: 10, station_1: 'F', station_2: 'F', station_name: 'F'},
];

describe('utils/splitIntoTrackSection.ts Tests 1', () => {
  test('splitIntoTrackSection: should handle correctly stops contain only start & end of stations', () => {
    const stops = ['A', 'F'];
    const result = splitFullTrackIntoTrackSections(tracks1, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'A', station_2: 'B', station_name: 'A'},
        {data: 2, station_1: 'A', station_2: 'B', station_name: null},
        {data: 3, station_1: 'A', station_2: 'B', station_name: null},
        {data: 4, station_1: 'B', station_2: 'C', station_name: 'B'},
        {data: 5, station_1: 'B', station_2: 'C', station_name: null},
        {data: 6, station_1: 'C', station_2: 'D', station_name: 'C'},
        {data: 7, station_1: 'D', station_2: 'E', station_name: 'D'},
        {data: 8, station_1: 'D', station_2: 'E', station_name: null},
        {data: 9, station_1: 'E', station_2: 'F', station_name: 'E'},
        {data: 10, station_1: 'F', station_2: 'F', station_name: 'F'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly (Case 1)', () => {
    const stops = ['A', 'B', 'F'];
    const result = splitFullTrackIntoTrackSections(tracks1, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'A', station_2: 'B', station_name: 'A'},
        {data: 2, station_1: 'A', station_2: 'B', station_name: null},
        {data: 3, station_1: 'A', station_2: 'B', station_name: null},
        {data: 4, station_1: 'B', station_2: 'B', station_name: 'B'},
      ],
      [
        {data: 4, station_1: 'B', station_2: 'C', station_name: 'B'},
        {data: 5, station_1: 'B', station_2: 'C', station_name: null},
        {data: 6, station_1: 'C', station_2: 'D', station_name: 'C'},
        {data: 7, station_1: 'D', station_2: 'E', station_name: 'D'},
        {data: 8, station_1: 'D', station_2: 'E', station_name: null},
        {data: 9, station_1: 'E', station_2: 'F', station_name: 'E'},
        {data: 10, station_1: 'F', station_2: 'F', station_name: 'F'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly (Case 2)', () => {
    const stops = ['A', 'D', 'E', 'F'];
    const result = splitFullTrackIntoTrackSections(tracks1, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'A', station_2: 'B', station_name: 'A'},
        {data: 2, station_1: 'A', station_2: 'B', station_name: null},
        {data: 3, station_1: 'A', station_2: 'B', station_name: null},
        {data: 4, station_1: 'B', station_2: 'C', station_name: 'B'},
        {data: 5, station_1: 'B', station_2: 'C', station_name: null},
        {data: 6, station_1: 'C', station_2: 'D', station_name: 'C'},
        {data: 7, station_1: 'D', station_2: 'D', station_name: 'D'},
      ],
      [
        {data: 7, station_1: 'D', station_2: 'E', station_name: 'D'},
        {data: 8, station_1: 'D', station_2: 'E', station_name: null},
        {data: 9, station_1: 'E', station_2: 'E', station_name: 'E'},
      ],
      [
        {data: 9, station_1: 'E', station_2: 'F', station_name: 'E'},
        {data: 10, station_1: 'F', station_2: 'F', station_name: 'F'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly stops containing all station', () => {
    const stops = ['A', 'B', 'C', 'D', 'E', 'F'];
    const result = splitFullTrackIntoTrackSections(tracks1, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'A', station_2: 'B', station_name: 'A'},
        {data: 2, station_1: 'A', station_2: 'B', station_name: null},
        {data: 3, station_1: 'A', station_2: 'B', station_name: null},
        {data: 4, station_1: 'B', station_2: 'B', station_name: 'B'},
      ],
      [
        {data: 4, station_1: 'B', station_2: 'C', station_name: 'B'},
        {data: 5, station_1: 'B', station_2: 'C', station_name: null},
        {data: 6, station_1: 'C', station_2: 'C', station_name: 'C'},
      ],
      [
        {data: 6, station_1: 'C', station_2: 'D', station_name: 'C'},
        {data: 7, station_1: 'D', station_2: 'D', station_name: 'D'},
      ],
      [
        {data: 7, station_1: 'D', station_2: 'E', station_name: 'D'},
        {data: 8, station_1: 'D', station_2: 'E', station_name: null},
        {data: 9, station_1: 'E', station_2: 'E', station_name: 'E'},
      ],
      [
        {data: 9, station_1: 'E', station_2: 'F', station_name: 'E'},
        {data: 10, station_1: 'F', station_2: 'F', station_name: 'F'},
      ],
    ]);
  });
});

const tracks2 = [
  {data: 1, station_1: 'TRTO', station_2: 'GUIL', station_name: 'TRTO'},
  {data: 2, station_1: 'TRTO', station_2: 'GUIL', station_name: null},
  {data: 3, station_1: 'GUIL', station_2: 'OSHA', station_name: 'GUIL'},
  {data: 4, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
  {data: 5, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
  {data: 6, station_1: 'OSHA', station_2: 'PHOP', station_name: 'OSHA'},
  {data: 7, station_1: 'PHOP', station_2: 'CBRG', station_name: 'PHOP'},
  {data: 8, station_1: 'PHOP', station_2: 'CBRG', station_name: null},
  {data: 9, station_1: 'CBRG', station_2: 'TRNJ', station_name: 'CBRG'},
  {data: 10, station_1: 'TRNJ', station_2: 'TRNJ', station_name: 'TRNJ'},
];

describe('utils/splitIntoTrackSection.ts Tests 2', () => {
  test('splitIntoTrackSection: should handle correctly stops contain only start & end of stations', () => {
    const stops = ['TRTO', 'TRNJ'];
    const result = splitFullTrackIntoTrackSections(tracks2, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'TRTO', station_2: 'GUIL', station_name: 'TRTO'},
        {data: 2, station_1: 'TRTO', station_2: 'GUIL', station_name: null},
        {data: 3, station_1: 'GUIL', station_2: 'OSHA', station_name: 'GUIL'},
        {data: 4, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 5, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 6, station_1: 'OSHA', station_2: 'PHOP', station_name: 'OSHA'},
        {data: 7, station_1: 'PHOP', station_2: 'CBRG', station_name: 'PHOP'},
        {data: 8, station_1: 'PHOP', station_2: 'CBRG', station_name: null},
        {data: 9, station_1: 'CBRG', station_2: 'TRNJ', station_name: 'CBRG'},
        {data: 10, station_1: 'TRNJ', station_2: 'TRNJ', station_name: 'TRNJ'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly (Case 1)', () => {
    const stops = ['TRTO', 'GUIL', 'TRNJ'];
    const result = splitFullTrackIntoTrackSections(tracks2, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'TRTO', station_2: 'GUIL', station_name: 'TRTO'},
        {data: 2, station_1: 'TRTO', station_2: 'GUIL', station_name: null},
        {data: 3, station_1: 'GUIL', station_2: 'GUIL', station_name: 'GUIL'},
      ],
      [
        {data: 3, station_1: 'GUIL', station_2: 'OSHA', station_name: 'GUIL'},
        {data: 4, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 5, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 6, station_1: 'OSHA', station_2: 'PHOP', station_name: 'OSHA'},
        {data: 7, station_1: 'PHOP', station_2: 'CBRG', station_name: 'PHOP'},
        {data: 8, station_1: 'PHOP', station_2: 'CBRG', station_name: null},
        {data: 9, station_1: 'CBRG', station_2: 'TRNJ', station_name: 'CBRG'},
        {data: 10, station_1: 'TRNJ', station_2: 'TRNJ', station_name: 'TRNJ'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly (Case 2)', () => {
    const stops = ['TRTO', 'PHOP', 'CBRG', 'TRNJ'];
    const result = splitFullTrackIntoTrackSections(tracks2, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'TRTO', station_2: 'GUIL', station_name: 'TRTO'},
        {data: 2, station_1: 'TRTO', station_2: 'GUIL', station_name: null},
        {data: 3, station_1: 'GUIL', station_2: 'OSHA', station_name: 'GUIL'},
        {data: 4, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 5, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 6, station_1: 'OSHA', station_2: 'PHOP', station_name: 'OSHA'},
        {data: 7, station_1: 'PHOP', station_2: 'PHOP', station_name: 'PHOP'},
      ],
      [
        {data: 7, station_1: 'PHOP', station_2: 'CBRG', station_name: 'PHOP'},
        {data: 8, station_1: 'PHOP', station_2: 'CBRG', station_name: null},
        {data: 9, station_1: 'CBRG', station_2: 'CBRG', station_name: 'CBRG'},
      ],
      [
        {data: 9, station_1: 'CBRG', station_2: 'TRNJ', station_name: 'CBRG'},
        {data: 10, station_1: 'TRNJ', station_2: 'TRNJ', station_name: 'TRNJ'},
      ],
    ]);
  });

  test('splitIntoTrackSection: should handle correctly stops containing all station', () => {
    const stops = ['TRTO', 'GUIL', 'OSHA', 'PHOP', 'CBRG', 'TRNJ'];
    const result = splitFullTrackIntoTrackSections(tracks2, stops);
    expect(result).toEqual([
      [
        {data: 1, station_1: 'TRTO', station_2: 'GUIL', station_name: 'TRTO'},
        {data: 2, station_1: 'TRTO', station_2: 'GUIL', station_name: null},
        {data: 3, station_1: 'GUIL', station_2: 'GUIL', station_name: 'GUIL'},
      ],
      [
        {data: 3, station_1: 'GUIL', station_2: 'OSHA', station_name: 'GUIL'},
        {data: 4, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 5, station_1: 'GUIL', station_2: 'OSHA', station_name: null},
        {data: 6, station_1: 'OSHA', station_2: 'OSHA', station_name: 'OSHA'},
      ],
      [
        {data: 6, station_1: 'OSHA', station_2: 'PHOP', station_name: 'OSHA'},
        {data: 7, station_1: 'PHOP', station_2: 'PHOP', station_name: 'PHOP'},
      ],
      [
        {data: 7, station_1: 'PHOP', station_2: 'CBRG', station_name: 'PHOP'},
        {data: 8, station_1: 'PHOP', station_2: 'CBRG', station_name: null},
        {data: 9, station_1: 'CBRG', station_2: 'CBRG', station_name: 'CBRG'},
      ],
      [
        {data: 9, station_1: 'CBRG', station_2: 'TRNJ', station_name: 'CBRG'},
        {data: 10, station_1: 'TRNJ', station_2: 'TRNJ', station_name: 'TRNJ'},
      ],
    ]);
  });
});