Skip to content

Commit c91dd56

Browse files
committed
only go workflow
1 parent 1acb8cc commit c91dd56

File tree

5 files changed

+171
-34
lines changed

5 files changed

+171
-34
lines changed

.github/workflows/nodejs-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Node.js Tests
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
# push:
5+
# branches:
6+
# - main
77
pull_request:
88
branches:
99
- main

.github/workflows/python-tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Python Tests
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
# push:
5+
# branches:
6+
# - main
77
pull_request:
88
branches:
99
- main

go/LinkedList/singly/LinkedList.go

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package singly
22

33
import "fmt"
44

@@ -196,30 +196,3 @@ func (ll *LinkedList) PrintList() {
196196
}
197197
fmt.Println("nil")
198198
}
199-
200-
func main() {
201-
ll := NewLinkedList()
202-
203-
// Adding data to the list
204-
ll.Append(1, "Node 1")
205-
ll.Append(2, "Node 2")
206-
ll.Append(3, "Node 3")
207-
208-
// Printing the list
209-
fmt.Println("List after adding nodes:")
210-
ll.PrintList()
211-
212-
// Deleting a node
213-
ll.DeleteAny(2)
214-
215-
// Printing the list after deletion
216-
fmt.Println("List after deleting a node:")
217-
ll.PrintList()
218-
219-
// Reversing the list
220-
ll.ReverseList()
221-
222-
// Printing the reversed list
223-
fmt.Println("List after reversing:")
224-
ll.PrintList()
225-
}
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
package singly
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestAppend(t *testing.T) {
8+
ll := NewLinkedList()
9+
ll.Append(1, "Node 1")
10+
ll.Append(2, "Node 2")
11+
ll.Append(3, "Node 3")
12+
13+
if ll.Size() != 3 {
14+
t.Errorf("Expected size 3, got %d", ll.Size())
15+
}
16+
17+
if ll.Find(1).data != "Node 1" || ll.Find(2).data != "Node 2" || ll.Find(3).data != "Node 3" {
18+
t.Errorf("Data mismatch")
19+
}
20+
}
21+
22+
func TestPrepend(t *testing.T) {
23+
ll := NewLinkedList()
24+
ll.Prepend(1, "Node 1")
25+
ll.Prepend(2, "Node 2")
26+
ll.Prepend(3, "Node 3")
27+
28+
if ll.Size() != 3 {
29+
t.Errorf("Expected size 3, got %d", ll.Size())
30+
}
31+
32+
if ll.head.data != "Node 3" {
33+
t.Errorf("Expected head data 'Node 3', got '%v'", ll.head.data)
34+
}
35+
if ll.tail.data != "Node 1" {
36+
t.Errorf("Expected tail data 'Node 1', got '%v'", ll.tail.data)
37+
}
38+
}
39+
40+
func TestDeleteHead(t *testing.T) {
41+
ll := NewLinkedList()
42+
ll.Append(1, "Node 1")
43+
ll.Append(2, "Node 2")
44+
ll.Append(3, "Node 3")
45+
46+
ll.DeleteHead()
47+
if ll.Size() != 2 {
48+
t.Errorf("Expected size 2, got %d", ll.Size())
49+
}
50+
if ll.head.data != "Node 2" {
51+
t.Errorf("Expected head data 'Node 2', got '%v'", ll.head.data)
52+
}
53+
}
54+
55+
func TestDeleteTail(t *testing.T) {
56+
ll := NewLinkedList()
57+
ll.Append(1, "Node 1")
58+
ll.Append(2, "Node 2")
59+
ll.Append(3, "Node 3")
60+
61+
ll.DeleteTail()
62+
if ll.Size() != 2 {
63+
t.Errorf("Expected size 2, got %d", ll.Size())
64+
}
65+
if ll.tail.data != "Node 2" {
66+
t.Errorf("Expected tail data 'Node 2', got '%v'", ll.tail.data)
67+
}
68+
}
69+
70+
func TestDeleteAny(t *testing.T) {
71+
ll := NewLinkedList()
72+
ll.Append(1, "Node 1")
73+
ll.Append(2, "Node 2")
74+
ll.Append(3, "Node 3")
75+
76+
ll.DeleteAny(2)
77+
if ll.Size() != 2 {
78+
t.Errorf("Expected size 2, got %d", ll.Size())
79+
}
80+
if ll.Find(2) != nil {
81+
t.Errorf("Expected nil, got %v", ll.Find(2))
82+
}
83+
if ll.head.next.data != "Node 3" {
84+
t.Errorf("Expected next node to be 'Node 3', got '%v'", ll.head.next.data)
85+
}
86+
}
87+
88+
func TestInsertBetween(t *testing.T) {
89+
ll := NewLinkedList()
90+
ll.Append(1, "Node 1")
91+
ll.Append(3, "Node 3")
92+
ll.InsertBetween(2, "Node 2", "Node 3", "Node 1")
93+
94+
if ll.Size() != 3 {
95+
t.Errorf("Expected size 3, got %d", ll.Size())
96+
}
97+
if ll.head.next.data != "Node 2" {
98+
t.Errorf("Expected next node to be 'Node 2', got '%v'", ll.head.next.data)
99+
}
100+
if ll.head.next.next.data != "Node 3" {
101+
t.Errorf("Expected next next node to be 'Node 3', got '%v'", ll.head.next.next.data)
102+
}
103+
}
104+
105+
func TestReverseList(t *testing.T) {
106+
ll := NewLinkedList()
107+
ll.Append(1, "Node 1")
108+
ll.Append(2, "Node 2")
109+
ll.Append(3, "Node 3")
110+
111+
ll.ReverseList()
112+
113+
if ll.head.data != "Node 3" {
114+
t.Errorf("Expected head data 'Node 3', got '%v'", ll.head.data)
115+
}
116+
if ll.head.next.data != "Node 2" {
117+
t.Errorf("Expected next node to be 'Node 2', got '%v'", ll.head.next.data)
118+
}
119+
if ll.head.next.next.data != "Node 1" {
120+
t.Errorf("Expected next next node to be 'Node 1', got '%v'", ll.head.next.next.data)
121+
}
122+
}
123+
124+
func TestClear(t *testing.T) {
125+
ll := NewLinkedList()
126+
ll.Append(1, "Node 1")
127+
ll.Append(2, "Node 2")
128+
ll.Append(3, "Node 3")
129+
130+
ll.Clear()
131+
if ll.Size() != 0 {
132+
t.Errorf("Expected size 0, got %d", ll.Size())
133+
}
134+
if ll.head != nil || ll.tail != nil {
135+
t.Errorf("Expected head and tail to be nil")
136+
}
137+
}
138+
139+
func TestFind(t *testing.T) {
140+
ll := NewLinkedList()
141+
ll.Append(1, "Node 1")
142+
ll.Append(2, "Node 2")
143+
144+
node := ll.Find(1)
145+
if node == nil {
146+
t.Errorf("Expected node with id 1, got nil")
147+
}
148+
if node.data != "Node 1" {
149+
t.Errorf("Expected node data 'Node 1', got '%v'", node.data)
150+
}
151+
}
152+
153+
func TestSize(t *testing.T) {
154+
ll := NewLinkedList()
155+
ll.Append(1, "Node 1")
156+
ll.Append(2, "Node 2")
157+
158+
if ll.Size() != 2 {
159+
t.Errorf("Expected size 2, got %d", ll.Size())
160+
}
161+
}

go/LinkedList/singly/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/harris-ahmad/DataStructuresAndAlgorithms/go/LinkedList/singly
2+
3+
go 1.22.5

0 commit comments

Comments
 (0)