deno.land / std@0.224.0 / collections / sample_test.ts
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../assert/mod.ts";import { sample } from "./sample.ts";
Deno.test({ name: "sample() handles no mutation", fn() { const array = ["a", "abc", "ba"]; sample(array);
assertEquals(array, ["a", "abc", "ba"]); },});
Deno.test({ name: "sample() handles empty input", fn() { const actual = sample([]); assertEquals(actual, undefined); },});
Deno.test({ name: "sample() handles array of numbers", fn() { const input = [1, 2, 3]; const actual = sample([1, 2, 3]);
assert(actual && input.includes(actual)); },});
Deno.test({ name: "sample() handles array of objects", fn() { const input = [ { name: "Anna", age: 18, }, { name: "Kim", age: 24, }, ]; const actual = sample(input);
assert(actual && input.includes(actual)); },});
Version Info