mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
52 lines
964 B
TypeScript
52 lines
964 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assert, assertEquals } from "@std/assert";
|
|
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));
|
|
},
|
|
});
|