deno.land / std@0.224.0 / collections / zip_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { zip } from "./zip.ts";
function zip1Test<T>( input: [Array<T>], expected: Array<[T]>, message?: string,) { const actual = zip(...input); assertEquals(actual, expected, message);}
assertEquals(zip([]), []);
Deno.test({ name: "zip() handles one array", fn() { zip1Test([ [1, 2, 3], ], [[1], [2], [3]]); },});
function zipTest<T, U>( input: [ReadonlyArray<T>, ReadonlyArray<U>], expected: Array<[T, U]>, message?: string,) { const actual = zip(...input); assertEquals(actual, expected, message);}
function zip3Test<T, U, V>( input: [Array<T>, Array<U>, Array<V>], expected: Array<[T, U, V]>, message?: string,) { const actual = zip(...input); assertEquals(actual, expected, message);}
Deno.test({ name: "zip() handles three arrays", fn() { zip3Test([ [1, 2, 3], [4, 5, 6], [7, 8, 9], ], [[1, 4, 7], [2, 5, 8], [3, 6, 9]]); },});
Deno.test({ name: "zip() handles three arrays when the first is the shortest", fn() { zip3Test([ [1, 2], [4, 5, 6], [7, 8, 9], ], [[1, 4, 7], [2, 5, 8]]); },});
Deno.test({ name: "zip() handles no mutation", fn() { const arrayA = [1, 4, 5]; const arrayB = ["foo", "bar"]; zip(arrayA, arrayB);
assertEquals(arrayA, [1, 4, 5]); assertEquals(arrayB, ["foo", "bar"]); },});
Deno.test({ name: "zip() handles empty input", fn() { zipTest( [[], []], [], ); zipTest( [[1, 2, 3], []], [], ); zipTest( [[], [{}, []]], [], ); assertEquals(zip(), []); },});
Deno.test({ name: "zip() handles same length", fn() { zipTest( [ [1, 4, 5], ["foo", "bar", "lorem"], ], [ [1, "foo"], [4, "bar"], [5, "lorem"], ], ); zipTest( [ [2.2, false], ["test", true], ], [ [2.2, "test"], [false, true], ], ); },});
Deno.test({ name: "zip() handles first shorter", fn() { zipTest( [ [1], ["foo", "bar", "lorem"], ], [[1, "foo"]], ); zipTest( [ [2.2, false], ["test", true, {}], ], [ [2.2, "test"], [false, true], ], ); },});
Deno.test({ name: "zip() handles second shorter", fn() { zipTest( [ [1, 4, 5], ["foo"], ], [[1, "foo"]], ); zipTest( [ [2.2, false, "test"], ["test", true], ], [ [2.2, "test"], [false, true], ], ); },});
Version Info