Commit 5268cb85 authored by John Chilton's avatar John Chilton
Browse files

Declarative testing of auto-pairing code.

parent 514c169e
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
- doc: Simple _R1 _R2 fastqs split.
  inputs:
  - input_R1.fastq
  - input_R2.fastq
  paired:
    input:
      forward: input_R1.fastq
      reverse: input_R2.fastq

- doc: Joining common prefixes on _R1 _R2.
  inputs:
  - input541_R1.fastq
  - input541_R2.fastq
  - input521_R1.fastq
  - input521_R2.fastq
  paired:
    input541:
      forward: input541_R1.fastq
      reverse: input541_R2.fastq
    input521:
      forward: input521_R1.fastq
      reverse: input521_R2.fastq

- doc: Simple .1.fastq/.2.fastq split.
  inputs:
  - input.1.fastq
  - input.2.fastq
  paired:
    input:
      forward: input.1.fastq
      reverse: input.2.fastq

- doc: Simple _1/_2 split.
  inputs:
  - input_1.fastq
  - input_2.fastq
  paired:
    input:
      forward: input_1.fastq
      reverse: input_2.fastq
+30 −0
Original line number Diff line number Diff line
import AUTO_PAIRING_SPECIFICATION from "./auto_pairing_spec.yml";
import {
    autoDetectPairs,
    autoPairWithCommonFilters,
@@ -117,3 +118,32 @@ describe("splitIntoPairedAndUnpaired", () => {
        expect(summary.pairs).toHaveLength(0);
    });
});

interface ExpectedPair {
    name: string;
    forward: string;
    reverse: string;
}

interface AutoPairingTest {
    doc?: string;
    inputs: string[];
    paired: Record<string, ExpectedPair>;
}

describe("fulfills auto pairing specification ", () => {
    test("the specification", () => {
        const tests = AUTO_PAIRING_SPECIFICATION;
        tests.forEach((test: AutoPairingTest) => {
            const inputs = test.inputs.map((name) => mockDataset(name));
            const summary = autoPairWithCommonFilters(inputs, true);
            for (const name in test.paired) {
                const expectedPair = test.paired[name] as ExpectedPair;
                const pair = summary.pairs?.find((p) => p.name === name);
                expect(pair).toBeDefined();
                expect(pair?.forward.name).toEqual(expectedPair.forward);
                expect(pair?.reverse.name).toEqual(expectedPair.reverse);
            }
        });
    });
});