c # – Implementation of the linked list with the unit test

I want to see how other people think of my code, so here it is. This is the first time I write a unit test. I wonder if there should be more tests for the LinkedList class and also if I write them correctly.

I have made the class Node public so that I can use it later for a binary tree implementation.

namespace DataStructuresAndAlgorithms.DataStructures
{
Public class node
    {
public T Data {get; together; }
public node Next {get; together; }
public node Previous {get; together; }

Node public () {}

public node (T t)
{
Data = t;
}
}
}

Implementation

using the system;
using System.Collections.Generic;

namespace DataStructuresAndAlgorithms.DataStructures
{
Public class LinkedList
    {
public node Head {get; private ensemble; }
public node Queue {get; private ensemble; }

public LinkedList (Node node)
{
Head = node;
Queue = node;
}

empty public AddToFirst (Node add)
{
toAdd.Next = Head;
Head = toAdd;
}

public void AddToLast (Node add)
{
Tail.Next = toAdd;
Queue = to add;
}

public void RemoveFirst ()
{
Head = Head.Next;
}

public void RemoveLast ()
{
pointer var = head;
while (pointer.Next! = Tail)
{
pointer = pointer.Next;
}
// the pointer is now before the tail
Queue = pointer;
Tail.Next = null;
}

Public IEnumerator <Node> GetEnumerator ()
{
pointer var = head;
while (pointer! = null)
{
yield return pointer;
pointer = pointer.Next;
}
}
}
}

Unit test

using the system;
using Xunit;

using DataStructuresAndAlgorithms.DataStructures;

Namespace DataStructuresAndAlgorithms.DataStructures.Tests
{
Public class LinkedListTest
{
        [Fact]
        public void AddToFirst_Node_Should_Become_Head ()
{
// Organize
var myLinkedList = new LinkedList(new node(45));

// Act
var nodeToAdd = new node(67);
myLinkedList.AddToFirst (nodeToAdd);

// Assert
var theNode = GetNodeFromList(myLinkedList, nodeToAdd);
Assert.Equal (nodeToAdd, theNode);
Assert.Equal (45, theNode.Next.Data);
}

        [Fact]
        public void AddToLast_Node_Should_Become_Tail ()
{
// Organize
var myLinkedList = new LinkedList(new node(35));

// Act
var nodeToAdd = new node(14);
myLinkedList.AddToLast (nodeToAdd);

// Assert
var theNode = GetNodeFromList(myLinkedList, nodeToAdd);
Assert.Equal (nodeToAdd, theNode);
}

        [Fact]
        public void RemoveFirst_Next_Node_Should_Be_Head ()
{
// Organize
var myLinkedList = new LinkedList(new node(777));

var node1 = new node(1);
myLinkedList.AddToLast (node1);

var node2 = new node(2);
myLinkedList.AddToLast (node2);

var node3 = new node(3);
myLinkedList.AddToLast (node3);

// Act
myLinkedList.RemoveFirst ();

// Assert
var theNode = GetNodeFromList(myLinkedList, node1);
Assert.Equal (node1, myLinkedList.Head);
}

        [Fact]
        public void RemoveLast_Next_Node_Should_Be_Tail ()
{
// Organize
var myLinkedList = new LinkedList(new node(777));

var node1 = new node(1);
myLinkedList.AddToLast (node1);

var node2 = new node(2);
myLinkedList.AddToLast (node2);

var node3 = new node(3);
myLinkedList.AddToLast (node3);

// Act
myLinkedList.RemoveLast ();

// Assert
var theNode = GetNodeFromList(myLinkedList, node2);
Assert.Equal (node2, myLinkedList.Tail);
}

public static node GetNodeFromList(LinkedList someLinkedList, Node a node) where T: struct
{
using (var itr = someLinkedList.GetEnumerator ())
{
while (itr.Current! = someNode)
{
itr.MoveNext ();
}
return itr.Current;
}
}
}
}

Presentation

using the system;
using System.Collections;

using DataStructuresAndAlgorithms.DataStructures;

Namespace DataStructuresAndAlgorithms.Presentation.Console
{
class program
{
static void Main (string[] args)
{
RunNode ();
System.Console.WriteLine ();
RunLinkedList ();
}

RunNode () static vacuum
{
System.Console.WriteLine ("Running the Node class");
System.Console.WriteLine ("----------------------");
var myNode = new node(32);
System.Console.WriteLine (myNode.Data);
}

RunLinkedList ()
{
System.Console.WriteLine ("Running the LinkedList class");
System.Console.WriteLine ("----------------------------");
var myLinkedList = new LinkedList(new node(99));
myLinkedList.AddToFirst (new node(56));
myLinkedList.AddToFirst (new node(23));
myLinkedList.AddToFirst (new node(33));
myLinkedList.AddToLast (new node(8888));
myLinkedList.RemoveLast ();
myLinkedList.RemoveFirst ();
System.Console.WriteLine ("HEAD =" + myLinkedList.Head.Data);
System.Console.WriteLine ("TAIL =" + myLinkedList.Tail.Data);

using (var linkedListEnumerator = myLinkedList.GetEnumerator ())
{
while (linkedListEnumerator.MoveNext ())
{
System.Console.WriteLine (linkedListEnumerator.Current.Data);
}
}
}
}
}

`` `