ThePrimeagen / kata-machine

1.28k stars 1.27k forks source link

No tests for insertAt for lists #62

Open kjbrown-sandbox opened 1 year ago

kjbrown-sandbox commented 1 year ago

DoublyLinkedList (as well as all the other list types) don't have any testing for the function insertAt. Also, a few of the other functions could be tested more thoroughly. I added some tests to the file on a branch and could make a PR if I were given permission; otherwise, here's the updated file:


export function test_list(list: List<number>): void {
    list.append(5);
    list.append(7);
    list.append(9);

    expect(list.get(2)).toEqual(9);
    expect(list.removeAt(1)).toEqual(7);
    expect(list.length).toEqual(2);
    expect(list.get(1)).toEqual(9);

    list.append(11);
    list.append(15);
    expect(list.removeAt(1)).toEqual(9);
    expect(list.remove(9)).toEqual(undefined);
    expect(list.removeAt(0)).toEqual(5);
    expect(list.removeAt(1)).toEqual(15);
    expect(list.removeAt(0)).toEqual(11);
    expect(list.length).toEqual(0);

    list.prepend(5);
    list.prepend(7);
    list.prepend(9);

    expect(list.get(2)).toEqual(5);
    expect(list.get(0)).toEqual(9);
    expect(list.remove(9)).toEqual(9);
    expect(list.length).toEqual(2);
    expect(list.get(0)).toEqual(7);

    list.insertAt(10, 0);
    list.insertAt(13, 2);
    list.insertAt(1, 4);

    expect(list.get(0)).toEqual(10);
    expect(list.get(1)).toEqual(7);
    expect(list.get(2)).toEqual(13);
    expect(list.get(3)).toEqual(5);
    expect(list.get(4)).toEqual(1);
    expect(list.insertAt(6, 6)).toEqual(undefined);
    expect(list.length).toEqual(5);
}
FX-Wood commented 1 year ago

I also had this problem. You should fork the repo and make a pull request that way. That's the normal way to open PRs to repositories you don't own. The rough steps are:

  1. make a fork of the repo ( https://docs.github.com/en/get-started/quickstart/fork-a-repo )
  2. either clone that and remake your branch (bonus if you want to try pushing the existing branch to the fork)
  3. open a PR from your fork to this repo ( https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork )