Skip to content

Commit 8cfdb2f

Browse files
authored
doc: fix: Added documentations that works with the autogenerated documentation (TheAlgorithms#339)
* doc: fix: Add documentation that works with the autogenerated documentation * Update go.mod to accept go version 1.17 * test: add a few tests for one of the issues
1 parent 59b98b8 commit 8cfdb2f

35 files changed

+138
-32
lines changed
File renamed without changes.
File renamed without changes.

cipher/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package cipher is a package containing different implementations of certain ciphers
2+
package cipher
File renamed without changes.
File renamed without changes.

ciphers/rot13/rot13.go renamed to cipher/rot13/rot13.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package rot13
44

55
import (
6-
"github.com/TheAlgorithms/Go/ciphers/caesar"
6+
"github.com/TheAlgorithms/Go/cipher/caesar"
77
)
88

99
// rot13 is a special case, which is fixed the shift of 13, of the Caesar cipher
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

conversion/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package conversion is a package of implementations which converts one data structure to another.
2+
package conversion

conversions/romantointeger.go renamed to conversion/romantointeger.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/*
2-
This algorithm will convert a standard roman number to an integer
3-
https://en.wikipedia.org/wiki/Roman_numerals
4-
Function receives a string as a roman number and outputs an integer
5-
Maximum output will be 3999
6-
Only standard form is supported
7-
*/
8-
package conversions
1+
// This algorithm will convert a standard roman number to an integer
2+
// https://en.wikipedia.org/wiki/Roman_numerals
3+
// Function receives a string as a roman number and outputs an integer
4+
// Maximum output will be 3999
5+
// Only standard form is supported
6+
7+
package conversion
98

109
var romans = map[string]int{"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}
1110

conversions/romantointeger_test.go renamed to conversion/romantointeger_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package conversions
1+
package conversion
22

33
import "testing"
44

dynamic/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package dynamic is a package of certain implementations of dynamically run algorithms.
2+
package dynamic

dynamic/matrixmultiplication.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://en.wikipedia.org/wiki/Matrix_chain_multiplication
33
// www.geeksforgeeks.org/dynamic_programming-set-8-matrix-chain-multiplication/
44

5-
// Package dynamic_programming Package for dynamically run algorithms
65
package dynamic
76

87
// MatrixChainRec function

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/TheAlgorithms/Go
22

3-
go 1.15
3+
go 1.17

graph/breadthfirstsearch.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Package graph demonstates Graph search algorithms
2-
// reference: https://en.wikipedia.org/wiki/Tree_traversal
31
package graph
42

53
// BreadthFirstSearch is an algorithm for traversing and searching graph data structures.

graph/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package graph demonstates Graph search algorithms
2+
// reference: https://en.wikipedia.org/wiki/Tree_traversal
3+
package graph

math/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package math is a package that contains mathematical algorithms and its different implementations.
2+
package math

math/doc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Empty test file to keep track of all the tests for the algorithms.
2+
3+
package math

math/max/max.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package max
2+
3+
// Int gives max of two integers
4+
// defining it here to be used in other subpackages of the repo.
5+
func Int(x int, y int) int {
6+
if x < y {
7+
return y
8+
}
9+
return x
10+
}

math/max/max_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package max
2+
3+
import "testing"
4+
5+
func TestMax(t *testing.T) {
6+
testCases := []struct {
7+
name string
8+
left int
9+
right int
10+
max int
11+
}{
12+
{
13+
name: "Left is max",
14+
left: 10,
15+
right: 9,
16+
max: 10,
17+
},
18+
{
19+
name: "right is max",
20+
left: 1,
21+
right: 10,
22+
max: 10,
23+
},
24+
}
25+
26+
for _, test := range testCases {
27+
t.Run(test.name, func(t *testing.T) {
28+
returnedMax := Int(test.left, test.right)
29+
if returnedMax != test.max {
30+
t.Errorf("Failed test %s\n\tleft: %v, right: %v, max: %v but received: %v",
31+
test.name, test.left, test.right, test.max, returnedMax)
32+
}
33+
})
34+
}
35+
}

other/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package other is dedicated to algorithms that
2+
// do not quite fit into any of the other subpackages in this repository.
3+
package other
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
/* O(n) solution, for calculating
22
maximum contiguous sum in the given array. */
33

4+
// Package maxsubarraysum is a package containing a solution to a common
5+
// problem of finding max contigious sum within a array of ints.
46
package maxsubarraysum
57

6-
// Max - already defined somewhere in this repository TODO: remove this definition and add the import path
7-
func Max(x int, y int) int {
8-
if x < y {
9-
return y
10-
}
11-
return x
12-
}
8+
import (
9+
"github.com/TheAlgorithms/Go/math/max"
10+
)
1311

1412
// MaxSubarraySum returns the maximum subarray sum
1513
func MaxSubarraySum(array []int) int {
16-
var currentMax int = 0
17-
var maxTillNow int = 0
14+
var currentMax int
15+
var maxTillNow int
16+
if len(array) != 0 {
17+
currentMax = array[0]
18+
maxTillNow = array[0]
19+
}
1820
for _, v := range array {
19-
currentMax = Max(v, currentMax+v)
20-
maxTillNow = Max(maxTillNow, currentMax)
21+
currentMax = max.Int(v, currentMax+v)
22+
maxTillNow = max.Int(maxTillNow, currentMax)
2123
}
2224
return maxTillNow
2325
}
24-
25-
// func main() {
26-
// array := []int{-2, -5, 6, 0, -2, 0, -3, 1, 0, 5, -6}
27-
// fmt.Println("Maximum contiguous sum: ", maxSubarraySum(array))
28-
// }
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package maxsubarraysum
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestMaxSubarraySum(t *testing.T) {
8+
testCases := []struct {
9+
name string
10+
slice []int
11+
expected int
12+
}{
13+
{
14+
name: "Empty slice",
15+
slice: []int{},
16+
expected: 0,
17+
},
18+
{
19+
name: "Max is 0",
20+
slice: []int{0, -1, -2, -4, -5},
21+
expected: 0,
22+
},
23+
{
24+
name: "Max is -1",
25+
slice: []int{-1, -3, -2, -5, -7},
26+
expected: -1,
27+
},
28+
{
29+
name: "Max is 7",
30+
slice: []int{-2, -5, 6, 0, -2, 0, -3, 1, 0, 5, -6},
31+
expected: 7,
32+
},
33+
}
34+
for _, test := range testCases {
35+
t.Run(test.name, func(t *testing.T) {
36+
if result := MaxSubarraySum(test.slice); result != test.expected {
37+
t.Fatalf("%s\n\tslice: %v, expected: %v, returned: %v", test.name, test.slice, test.expected, result)
38+
}
39+
})
40+
}
41+
}

other/nested/nestedbrackets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package nested_brackets provides functions for testing
1+
// Package nested provides functions for testing
22
// strings propper brackets nesting.
33
package nested
44

other/password/generator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// You must provide a minimum length and a maximum length
33
// This length is not fixed if you generate multiple passwords for the same range
44

5-
package password_generator
5+
// Package password contains functions to help generate random passwords
6+
package password
67

78
import (
89
"crypto/rand"

search/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package search is a subpackage dedicated to all searching algorithms related to slices/arrays.
2+
package search

strings/doc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package strings is a package that contains all algorithms
2+
// that are used to analyse and manipulate strings.
3+
package strings
File renamed without changes.

structure/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package structure is a subpackage that is dedicated to
2+
// different implementations of data structures in the
3+
// domain of computer science.
4+
package structure

0 commit comments

Comments
 (0)