RSSAmplifier

Hello there. on xrazis · Haris Razis · Apr 19, 2026

Test driven technical interview

0
Sign in to vote or save

Haris Razis · xrazis.com

You know what they say; if you can’t beat them, join them.

By the time you are reading this, the repository structure might have changed a bit. You will find the repository link at the very end of this post. What is described here still applies.

The set up

I have set up a repository with five distinct directories.

.
├── data-structures
├── leetcode
├── problem-solving-patterns
├── searching-algorithms
└── sorting-algorithms

Each directory corresponds to the relevant section I am studying for. Let’s take for example a singly linked list. I would create the main and test files under data-structures.

data-structures
├── singly-linked-list.js
└── singly-linked-list.test.js

In the main file goes the code. Bellow, is the implementation for the linked list example we are talking about. The two necessary classes are defined alongside the named export needed for the tests. For the sake of brevity I have only included the push method of SinglyLinkedList.

class Node {
  constructor(val) {
    this.val = val;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.head = null;
    this.tail = null;
    this.length = 0;
  }

  push(val) {
    const newNode = new Node(val);

    if (!this.head) {
      this.head = newNode;
      this.tail = this.head;
    } else {
      this.tail.next = newNode;
      this.tail = newNode;
    }

    this.length++;

    return this;
  }
}

export { SinglyLinkedList };

In the test file I place the different cases. I like the test driven approach as I also get to practice on writing tests.

import { expect, test, describe } from "bun:test";
import { SinglyLinkedList } from "./singly-linked-list.js";

describe("SinglyLinkedList", () => {
  test("should push to list", () => {
    const list = new SinglyLinkedList();
    list.push("first");
    expect(list.length).toBe(1);
    expect(list.head.val).toBe("first");
    expect(list.tail.val).toBe("first");

    list.push("second");
    expect(list.length).toBe(2);
    expect(list.head.val).toBe("first");
    expect(list.tail.val).toBe("second");
  });
}

Finally, I use bun to run the tests. It comes with a built in test runner so no extra setup is needed.

➜ bun test singly-linked-list.test.js --test-name-pattern "should push to list"
bun test v1.3.11 (af24e281)

data-structures/singly-linked-list.test.js:
✓ SinglyLinkedList > should push to list [1.00ms]

 1 pass
 8 filtered out
 0 fail
 6 expect() calls
Ran 1 test across 1 file. [8.00ms]

Resources

Read the original on xrazis.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.