Skip to content

Commit

Permalink
Merge pull request #23 from Farischt/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
farischt authored Jan 22, 2023
2 parents f835578 + 669869f commit 1580642
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 176 deletions.
11 changes: 11 additions & 0 deletions .github/issue-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defaultBranch: "dev"
openPR: true
autoCloseIssue: true
copyIssueDescriptionToPR: true
copyIssueLabelsToPR: true
copyIssueAssigneeToPR: true
copyIssueProjectsToPR: true
copyIssueMilestoneToPR: true
prSkipCI: true
commentMessage: "Branch ${branchName} created for issue: ${issue.title}"
branchName: "${issue.number}-${issue.title,}"
29 changes: 0 additions & 29 deletions .github/workflows/super-linter.yml

This file was deleted.

120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,124 @@ Here is a list of the different packages :

`ds/tree` and `ds/linked_list` have each a separated `Node` structure.

## How to use the different data structures

### Queue

In order to create a queue:

```go
import (
"github.com/farischt/ds/queue"
)

func main() {
capacity := 1
q := queue.New[int](capacity)
// You can now use any method implementend in IQueue as seen in docs.
}
```

### Stack

In order to create a stack:

```go
import (
"github.com/farischt/ds/stack"
)

func main() {
capacity := 1
s := stack.New[int](capacity)
// You can now use any method implementend in IStack as seen in docs.
}
```

### Linked list

In order to create a linked list:

```go
import (
"github.com/farischt/ds/linked_list"
)

func main() {
l := ll.New[int]()
// You can now use any method implementend in ILinkedList as seen in docs.
}
```

### Binary search tree

In order to create a binary search tree:

```go
import (
"github.com/farischt/ds/tree"
)

func main() {
rootData := 10
root := tree.NewNode(rootData)
l := tree.New(root)
// You can now use any method implementend in IBinarySearchTree as seen in docs.
}
```

### Graph

In order to create a graph:

```go
import (
"github.com/farischt/ds/graph"
)

func main() {
g := graph.New[int]()
// You can now use any method implementend in IGraph as seen in docs.

// Before adding any edge, make sure to create nodes.
src := 10
dst := 20
g.Add(src)
g.Add(dst)
g.AddUndirectedEdge(src, dst)
}
```

### Heap

In order to create a heap:

```go
import (
"github.com/farischt/ds/heap"
)

func main() {
minHeap := heap.New[int](heap.MinHeap)
maxHeap := heap.New[int](heap.MaxHeap)
// You can now use any method implementend in IGraph as seen in docs.

// In some case a heap could only contain a native number type (int, uint...).
data := 10 // This is the value used to compute the heap.
minHeap.Push(data, nil)

// On another hand, a heap could be use to store more than just a number. For example, in the diksjtra algorithm, we use a heap to store the value of a node and the current distance.
node := 10 // This is the value used to compute the heap.
distance := 30 // It could be any data type.
minHeap.Push(node, distance)


// If you pop the top element it will return an pointer of heap.Item.
item, _ := minHeap.Pop()

// This item has to fields Value (the node value) and Information (in the previous case, it will be the distance 30).
// Refer to the heap.Item docs for more informations.
}
```

For more information about the various methods please refere to the [package documentation](https://pkg.go.dev/github.com/farischt/ds).
35 changes: 17 additions & 18 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"testing"
)

func Test_New(t *testing.T) {
func TestNew(t *testing.T) {
graph := New[int]()
fmt.Println(graph.nodes)
if graph.nodes == nil {
t.Errorf("nodes should be initialized, test new graph.")
}
}

func Test_Add(t *testing.T) {
func TestAdd(t *testing.T) {
data := 1
graph := New[int]()
graph.Add(data)
Expand All @@ -22,7 +22,7 @@ func Test_Add(t *testing.T) {
}
}

func Test_AddDirectedEdge(t *testing.T) {
func TestAddDirectedEdge(t *testing.T) {
src := 1
dst := 2
graph := New[int]()
Expand All @@ -34,7 +34,7 @@ func Test_AddDirectedEdge(t *testing.T) {
}
}

func Test_AddUndirectedEdge(t *testing.T) {
func TestAddUndirectedEdge(t *testing.T) {
src := 1
dst := 2
graph := New[int]()
Expand All @@ -49,7 +49,7 @@ func Test_AddUndirectedEdge(t *testing.T) {
}
}

func Test_HasPath(t *testing.T) {
func TestHasPath(t *testing.T) {
src := 1
dst := 5
graph := New[int]()
Expand All @@ -67,7 +67,7 @@ func Test_HasPath(t *testing.T) {
}
}

func Test_HasPathWithInvalidSrc(t *testing.T) {
func TestHasPathWithInvalidSrc(t *testing.T) {
src := 0
dst := 5
graph := New[int]()
Expand All @@ -85,7 +85,7 @@ func Test_HasPathWithInvalidSrc(t *testing.T) {
}
}

func Test_HasPathWithInvalidDst(t *testing.T) {
func TestHasPathWithInvalidDst(t *testing.T) {
src := 1
dst := 0
graph := New[int]()
Expand All @@ -103,7 +103,7 @@ func Test_HasPathWithInvalidDst(t *testing.T) {
}
}

func Test_HasPathWithSameSrcDst(t *testing.T) {
func TestHasPathWithSameSrcDst(t *testing.T) {
src := 1
graph := New[int]()
graph.Add(src)
Expand All @@ -113,7 +113,7 @@ func Test_HasPathWithSameSrcDst(t *testing.T) {
}
}

func Test_ComponentCount(t *testing.T) {
func TestComponentCount(t *testing.T) {
expectedCount := 1
graph := New[int]()
graph.Add(1)
Expand All @@ -125,7 +125,7 @@ func Test_ComponentCount(t *testing.T) {
}
}

func Test_ComponentCountEmpty(t *testing.T) {
func TestComponentCountEmpty(t *testing.T) {
expectedCount := 0
graph := New[int]()

Expand All @@ -134,7 +134,7 @@ func Test_ComponentCountEmpty(t *testing.T) {
}
}

func Test_ComponentCountWithTwoComponents(t *testing.T) {
func TestComponentCountWithTwoComponents(t *testing.T) {
expectedCount := 2
graph := New[int]()
graph.Add(1)
Expand All @@ -150,7 +150,7 @@ func Test_ComponentCountWithTwoComponents(t *testing.T) {
}
}

func Test_LargestComponentSizeWithOneComponent(t *testing.T) {
func TestLargestComponentSizeWithOneComponent(t *testing.T) {
expectedSize := 5
graph := New[int]()
graph.Add(1)
Expand All @@ -172,7 +172,7 @@ func Test_LargestComponentSizeWithOneComponent(t *testing.T) {
}
}

func Test_LargestComponentSizeWithTwoComponents(t *testing.T) {
func TestLargestComponentSizeWithTwoComponents(t *testing.T) {
expectedSize := 5
graph := New[int]()
graph.Add(1)
Expand All @@ -199,8 +199,7 @@ func Test_LargestComponentSizeWithTwoComponents(t *testing.T) {
}
}


func Test_ShortestPath(t *testing.T) {
func TestShortestPath(t *testing.T) {
src := 1
dst := 5
graph := New[int]()
Expand All @@ -213,14 +212,14 @@ func Test_ShortestPath(t *testing.T) {
graph.AddDirectedEdge(2, 3)
graph.AddDirectedEdge(3, 4)
graph.AddDirectedEdge(4, dst)
expectedPathLen := 4
expectedPathLen := 4
path := graph.ShortestPath(src, dst)
if path != expectedPathLen {
t.Errorf("shortest path should be %v lenght, test shortest path.", expectedPathLen)
}
}

func Test_ShortestPathWithInvalidSrc(t *testing.T) {
func TestShortestPathWithInvalidSrc(t *testing.T) {
src := 0
dst := 5
graph := New[int]()
Expand All @@ -239,7 +238,7 @@ func Test_ShortestPathWithInvalidSrc(t *testing.T) {
}
}

func Test_ShortestPathWithInvalidDst(t *testing.T) {
func TestShortestPathWithInvalidDst(t *testing.T) {
src := 1
dst := 0
graph := New[int]()
Expand Down
Loading

0 comments on commit 1580642

Please sign in to comment.