Server/project/tests/utils/collections/queue/Queue.test.ts
Refringe 5740774a46
Apply Biome Formatting
This is the result of running `npm run format` which applies the Biome formatting rules. Rejoice!
2024-07-23 11:12:53 -04:00

56 lines
1.8 KiB
TypeScript

import "reflect-metadata";
import { Queue } from "@spt/utils/collections/queue/Queue";
import { describe, expect, it } from "vitest";
describe("LinkedList", () => {
describe("enqueue", () => {
const queue = new Queue<number>();
queue.enqueue(420);
queue.enqueue(69);
queue.enqueue(8008135);
queue.enqueue(1337);
it("adds elements to the end of the queue", () => {
expect(queue.peek()).toEqual(420);
expect(queue.length).toEqual(4);
});
});
describe("enqueueAll", () => {
const queue = new Queue<number>();
queue.enqueueAll([420, 69, 8008135, 1337]);
it("iterates the array and adds each element to the end of the queue", () => {
expect(queue.peek()).toEqual(420);
expect(queue.length).toEqual(4);
});
});
describe("dequeue", () => {
const queue = new Queue<number>();
queue.enqueueAll([420, 69, 8008135, 1337]);
it("removes the first element and return it's value", () => {
expect(queue.dequeue()).toEqual(420);
expect(queue.peek()).toEqual(69);
expect(queue.length).toEqual(3);
expect(queue.dequeue()).toEqual(69);
expect(queue.peek()).toEqual(8008135);
expect(queue.length).toEqual(2);
expect(queue.dequeue()).toEqual(8008135);
expect(queue.peek()).toEqual(1337);
expect(queue.length).toEqual(1);
expect(queue.dequeue()).toEqual(1337);
expect(queue.peek()).toEqual(undefined);
expect(queue.length).toEqual(0);
expect(queue.dequeue()).toEqual(undefined);
expect(queue.peek()).toEqual(undefined);
expect(queue.length).toEqual(0);
});
});
});