Skip to content

Commit 7ea2964

Browse files
tjgurwara99github-actions
andauthored
Fix: Major restructuring for fixing the linting workflow errors and module style code writing. (#266)
* fix: Simple fixes on multiple files * fix: Removed the improper way of testing the caesar (sub)module * fix: properly configured the test * fix: properly configure rot13 * fix: fixed polybius test * fix: fixed xor cipher and its test * fix: Tried to correct the implemention so that the redeclaration error that appears in tests goes away. TODO: Maybe implement it with interfaces. * fix: simple fixes for the dynamic array file in order for it to work as a module * fix: added hashmap tests and removed main * fix: separated the linkedlists (singly and doubly) so that that there are no clashes with the definition of Nodes - can be simplified using an interface * fix: minor changes * fix: changes to dynamic programming (sub)module so that there are no redeclaration issues * feat: mod file for go get command * fix: simple restructuring of the directories * fix: TODO don't know what this function is for? * fix: restructuring * fix: restructure * fix: linting errors * fix: the automated errors in the golangci-lint for datastructures * fix: automated errors in dynamicprogramming with golangci-lint * fix: automated test errors in math directory with golangci-lint * fix: automated errors in graphs directory with golangci-lint * fix: automated errors in others directory and removed a duplicate that already existed in the math directory which I updated in the previous commit * fix: automated errors in strings directory. Still need to write tests for a lot of functions * fix: minor fixes by removing main * fix: commented out one test because it takes too long to run with go test command * fix: linting errors * feat: changes to workflow file * updating DIRECTORY.md * fix: minor naming fix for the algorithm package import in ciphers/rot13/rot13.go * feat: added automated tests: * fix: some issue with automated test: * fix: some testing issues * fix: automated test issue * fix: automated test issue * fix: test issues * fix: test issue for rsa * fix: ignoring rsa tests for test failures Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent a8f855d commit 7ea2964

File tree

70 files changed

+1840
-2032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1840
-2032
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@ jobs:
1818
# only-new-issues: true # Let's focus on this PR first
1919
- run: echo "/home/runner/golangci-lint-1.31.0-linux-amd64" >> $GITHUB_PATH
2020
- run: go version ; golangci-lint --version # Fix the following and remove || true
21-
- run: golangci-lint run --no-config ciphers
22-
- run: golangci-lint run --no-config datastructures/binary-tree || true
23-
- run: golangci-lint run --no-config datastructures/dynamic-array || true
24-
- run: golangci-lint run --no-config datastructures/hashmap
25-
- run: golangci-lint run --no-config datastructures/linkedlist || true
26-
- run: golangci-lint run --no-config datastructures/trie || true
27-
- run: golangci-lint run --no-config dynamicprogramming || true
28-
- run: golangci-lint run --no-config other || true
29-
- run: golangci-lint run --no-config searches || true
30-
- run: golangci-lint run --no-config sorts
31-
# - run: golangci-lint run --no-config strings/...
32-
- run: golangci-lint run --no-config "strings/multiple-string-matching" || true
21+
- run: golangci-lint run --no-config ciphers/...
22+
# - run: golangci-lint run --no-config datastructures/binary-tree || true
23+
# - run: golangci-lint run --no-config datastructures/dynamic-array || true
24+
# - run: golangci-lint run --no-config datastructures/hashmap
25+
# - run: golangci-lint run --no-config datastructures/linkedlist || true
26+
# - run: golangci-lint run --no-config datastructures/trie || true
27+
- run: golangci-lint run --no-config dynamicprogramming/...
28+
- run: golangci-lint run --no-config other/...
29+
- run: golangci-lint run --no-config searches/...
30+
- run: golangci-lint run --no-config sorts/...
31+
- run: golangci-lint run --no-config strings/...
32+
# - run: golangci-lint run --no-config "strings/multiple-string-matching" || true
3333
# - run: golangci-lint run --no-config "strings/single string matching" || true
34-
- run: golangci-lint run --no-config strings/levenshteindistance
35-
- run: golangci-lint run --no-config strings/naivesearch
36-
- run: golangci-lint run --no-config math/gcd
37-
- run: golangci-lint run --no-config math/power
38-
- run: golangci-lint run --no-config math/primecheck
39-
- run: golangci-lint run --no-config math/sieve || true
34+
# - run: golangci-lint run --no-config strings/levenshteindistance
35+
# - run: golangci-lint run --no-config strings/naivesearch
36+
- run: golangci-lint run --no-config math/...
37+
# - run: golangci-lint run --no-config math/gcd
38+
# - run: golangci-lint run --no-config math/power
39+
# - run: golangci-lint run --no-config math/primecheck
40+
# - run: golangci-lint run --no-config math/sieve || true

.github/workflows/golangtests.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: golang-tests
2+
on: [push, pull_request]
3+
jobs:
4+
golang-tests:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
fail-fast: false
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-go@v2
11+
- run: go version
12+
- name: Tests
13+
run: go test $(go list ./... | grep -v /sbom | grep -v /rsa)

DIRECTORY.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@
2929
* Binary-Tree
3030
* [Binarysearchtree](https://github.com/TheAlgorithms/Go/blob/master/datastructures/binary-tree/binarysearchtree.go)
3131
* [Binarytree](https://github.com/TheAlgorithms/Go/blob/master/datastructures/binary-tree/binarytree.go)
32+
* [Btree](https://github.com/TheAlgorithms/Go/blob/master/datastructures/binary-tree/btree.go)
33+
* [Node](https://github.com/TheAlgorithms/Go/blob/master/datastructures/binary-tree/node.go)
3234
* Dynamic-Array
3335
* [Dynamicarray](https://github.com/TheAlgorithms/Go/blob/master/datastructures/dynamic-array/dynamicarray.go)
3436
* Hashmap
3537
* [Hashmap](https://github.com/TheAlgorithms/Go/blob/master/datastructures/hashmap/hashmap.go)
3638
* [Hashmap Test](https://github.com/TheAlgorithms/Go/blob/master/datastructures/hashmap/hashmap_test.go)
3739
* Linkedlist
38-
* [Doublylinkedlist](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/doublylinkedlist.go)
39-
* Singlelinkedlist
40-
* [Single-Linkedlist](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlelinkedlist/single-linkedlist.go)
41-
* [Single-Linkedlist Test](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlelinkedlist/single-linkedlist_test.go)
42-
* [Singlylinkedlist](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlylinkedlist.go)
40+
* Doublylinkedlist
41+
* [Doublylinkedlist](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/doublylinkedlist/doublylinkedlist.go)
42+
* Singlylinkedlist
43+
* [Singlylinkedlist](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlylinkedlist/singlylinkedlist.go)
44+
* [Singlylinkedlist2](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlylinkedlist/singlylinkedlist2.go)
45+
* [Singlylinkedlist Test](https://github.com/TheAlgorithms/Go/blob/master/datastructures/linkedlist/singlylinkedlist/singlylinkedlist_test.go)
4346
* Trie
4447
* [Trie](https://github.com/TheAlgorithms/Go/blob/master/datastructures/trie/trie.go)
4548
* [Trie Test](https://github.com/TheAlgorithms/Go/blob/master/datastructures/trie/trie_test.go)
@@ -55,9 +58,12 @@
5558
* [Rod-Cutting](https://github.com/TheAlgorithms/Go/blob/master/dynamicprogramming/rod-cutting.go)
5659

5760
## Graphs
58-
* [Breathfirstsearch](https://github.com/TheAlgorithms/Go/blob/master/graphs/breathfirstsearch.go)
59-
* [Depthfirstsearch](https://github.com/TheAlgorithms/Go/blob/master/graphs/depthfirstsearch.go)
60-
* [Floydwarshall](https://github.com/TheAlgorithms/Go/blob/master/graphs/floydwarshall.go)
61+
* Breathfirstsearch
62+
* [Breathfirstsearch](https://github.com/TheAlgorithms/Go/blob/master/graphs/breathfirstsearch/breathfirstsearch.go)
63+
* Depthfirstsearch
64+
* [Depthfirstsearch](https://github.com/TheAlgorithms/Go/blob/master/graphs/depthfirstsearch/depthfirstsearch.go)
65+
* Floydwarshall
66+
* [Floydwarshall](https://github.com/TheAlgorithms/Go/blob/master/graphs/floydwarshall/floydwarshall.go)
6167

6268
## Math
6369
* Gcd
@@ -74,17 +80,20 @@
7480
* [Pythagoras Test](https://github.com/TheAlgorithms/Go/blob/master/math/pythagoras/pythagoras_test.go)
7581
* Sieve
7682
* [Sieve](https://github.com/TheAlgorithms/Go/blob/master/math/sieve/Sieve.go)
83+
* [Sieve Test](https://github.com/TheAlgorithms/Go/blob/master/math/sieve/sieve_test.go)
7784

7885
## Other
79-
* [Maxsubarraysum](https://github.com/TheAlgorithms/Go/blob/master/other/maxsubarraysum.go)
86+
* Maxsubarraysum
87+
* [Maxsubarraysum](https://github.com/TheAlgorithms/Go/blob/master/other/maxsubarraysum/maxsubarraysum.go)
8088
* Monte Carlo Pi
8189
* [Monte Carlo Pi](https://github.com/TheAlgorithms/Go/blob/master/other/monte_carlo_pi/monte_carlo_pi.go)
8290
* [Monte Carlo Pi Test](https://github.com/TheAlgorithms/Go/blob/master/other/monte_carlo_pi/monte_carlo_pi_test.go)
83-
* [Nestedbrackets](https://github.com/TheAlgorithms/Go/blob/master/other/nestedbrackets.go)
84-
* [Passwordgenerator](https://github.com/TheAlgorithms/Go/blob/master/other/passwordgenerator.go)
85-
* [Prime Numbers](https://github.com/TheAlgorithms/Go/blob/master/other/prime_numbers.go)
86-
* [Primenumbers](https://github.com/TheAlgorithms/Go/blob/master/other/PrimeNumbers.go)
87-
* [Stringcombinations](https://github.com/TheAlgorithms/Go/blob/master/other/stringcombinations.go)
91+
* Nestedbrackets
92+
* [Nestedbrackets](https://github.com/TheAlgorithms/Go/blob/master/other/nestedbrackets/nestedbrackets.go)
93+
* Passwordgenerator
94+
* [Passwordgenerator](https://github.com/TheAlgorithms/Go/blob/master/other/passwordgenerator/passwordgenerator.go)
95+
* Stringcombinations
96+
* [Stringcombinations](https://github.com/TheAlgorithms/Go/blob/master/other/stringcombinations/stringcombinations.go)
8897

8998
## Searches
9099
* [Binarysearch](https://github.com/TheAlgorithms/Go/blob/master/searches/binarysearch.go)
@@ -121,8 +130,10 @@
121130
* [Naivestringsearch](https://github.com/TheAlgorithms/Go/blob/master/strings/naivesearch/naiveStringSearch.go)
122131
* [Naivestringsearch Test](https://github.com/TheAlgorithms/Go/blob/master/strings/naivesearch/naiveStringSearch_test.go)
123132
* Single-String-Matching
124-
* [Bom](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/bom.go)
125-
* [Horspool](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/horspool.go)
133+
* Bom
134+
* [Bom](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/bom/bom.go)
135+
* Horspool
136+
* [Horspool](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/horspool/horspool.go)
126137
* Kmp
127138
* [Kmp](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/kmp/kmp.go)
128139
* [Kmp Test](https://github.com/TheAlgorithms/Go/blob/master/strings/single-string-matching/kmp/kmp_test.go)

ciphers/caesar/CaesarCipher.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22
// ref: https://en.wikipedia.org/wiki/Caesar_cipher
33
package caesar
44

5-
// Caesar is struct for Caesar cipher
6-
type Caesar struct {
7-
}
8-
9-
// NewCaesar returns a pointer to object of Caesar
10-
func NewCaesar() *Caesar {
11-
return &Caesar{}
12-
}
13-
145
// Encrypt encrypts by right shift of "key" each character of "input"
15-
func (c Caesar) Encrypt(input string, key int) string {
6+
func Encrypt(input string, key int) string {
167
// if key is negative value,
178
// updates "key" the number which congruents to "key" modulo 26
189
key = (key%26 + 26) % 26
@@ -32,7 +23,7 @@ func (c Caesar) Encrypt(input string, key int) string {
3223
}
3324

3425
// Decrypt decrypts by left shift of "key" each character of "input"
35-
func (c Caesar) Decrypt(input string, key int) string {
26+
func Decrypt(input string, key int) string {
3627
// left shift of "key" is same as right shift of 26-"key"
37-
return c.Encrypt(input, 26-key)
28+
return Encrypt(input, 26-key)
3829
}

ciphers/caesar/caesar_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
package caesar_test
1+
package caesar
22

33
import (
4-
"TheAlgorithms/Go/ciphers/caesar"
54
"fmt"
65
"testing"
76
)
87

9-
var c *caesar.Caesar = caesar.NewCaesar()
10-
118
func TestEncrypt(t *testing.T) {
129
var caesarTestData = []struct {
1310
description string
@@ -66,7 +63,7 @@ func TestEncrypt(t *testing.T) {
6663
}
6764
for _, test := range caesarTestData {
6865
t.Run(test.description, func(t *testing.T) {
69-
actual := c.Encrypt(test.input, test.key)
66+
actual := Encrypt(test.input, test.key)
7067
if actual != test.expected {
7168
t.Logf("FAIL: %s", test.description)
7269
t.Fatalf("With input string '%s' and key '%d' was expecting '%s' but actual was '%s'",
@@ -129,7 +126,7 @@ func TestDecrypt(t *testing.T) {
129126

130127
for _, test := range caesarTestData {
131128
t.Run(test.description, func(t *testing.T) {
132-
actual := c.Decrypt(test.input, test.key)
129+
actual := Decrypt(test.input, test.key)
133130
if actual != test.expected {
134131
t.Logf("FAIL: %s", test.description)
135132
t.Fatalf("With input string '%s' and key '%d' was expecting '%s' but actual was '%s'",
@@ -139,18 +136,16 @@ func TestDecrypt(t *testing.T) {
139136
}
140137
}
141138

142-
func ExampleNewCaesar() {
139+
func Example() {
143140
const (
144141
key = 10
145142
input = "The Quick Brown Fox Jumps over the Lazy Dog."
146143
)
147144

148-
c := caesar.NewCaesar()
149-
150-
encryptedText := c.Encrypt(input, key)
145+
encryptedText := Encrypt(input, key)
151146
fmt.Printf("Encrypt=> key: %d, input: %s, encryptedText: %s\n", key, input, encryptedText)
152147

153-
decryptedText := c.Decrypt(encryptedText, key)
148+
decryptedText := Decrypt(encryptedText, key)
154149
fmt.Printf("Decrypt=> key: %d, input: %s, decryptedText: %s\n", key, encryptedText, decryptedText)
155150

156151
// Output:

ciphers/polybius/polybius.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ func NewPolybius(key string, size int, chars string) (*Polybius, error) {
3535

3636
// Encrypt encrypts with polybius encryption
3737
func (p *Polybius) Encrypt(text string) (string, error) {
38-
chars := []rune(strings.ToUpper(text))
3938
encryptedText := ""
40-
for _, char := range chars {
39+
for _, char := range strings.ToUpper(text) {
4140
encryptedChar, err := p.encipher(char)
4241
if err != nil {
4342
return "", fmt.Errorf("failed encipher: %w", err)

ciphers/polybius/polybius_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package polybius_test
1+
package polybius
22

33
import (
4-
"TheAlgorithms/Go/ciphers/polybius"
54
"fmt"
65
"log"
76
"testing"
@@ -15,7 +14,7 @@ func ExampleNewPolybius() {
1514
characters = "HogeF"
1615
key = "abcdefghijklmnopqrstuvwxy"
1716
)
18-
p, err := polybius.NewPolybius(key, size, characters)
17+
p, err := NewPolybius(key, size, characters)
1918
if err != nil {
2019
log.Fatalf("failed NewPolybius: %v", err)
2120
}
@@ -61,7 +60,7 @@ func TestNewPolybius(t *testing.T) {
6160

6261
for _, tc := range cases {
6362
t.Run(tc.name, func(t *testing.T) {
64-
_, err := polybius.NewPolybius(tc.key, tc.size, tc.characters)
63+
_, err := NewPolybius(tc.key, tc.size, tc.characters)
6564
if err != nil && err.Error() != tc.wantErr {
6665
t.Errorf("failed NewPolybius: %v", err)
6766
}
@@ -89,7 +88,7 @@ func TestPolybiusEncrypt(t *testing.T) {
8988
characters = "HogeF"
9089
key = "abcdefghijklmnopqrstuvwxy"
9190
)
92-
p, err := polybius.NewPolybius(key, size, characters)
91+
p, err := NewPolybius(key, size, characters)
9392
if err != nil {
9493
t.Fatalf("failed NewPolybius: %v", err)
9594
}
@@ -133,7 +132,7 @@ func TestPolybiusDecrypt(t *testing.T) {
133132
characters = "HogeF"
134133
key = "abcdefghijklmnopqrstuvwxy"
135134
)
136-
p, err := polybius.NewPolybius(key, size, characters)
135+
p, err := NewPolybius(key, size, characters)
137136
if err != nil {
138137
t.Fatalf("failed NewPolybius: %v", err)
139138
}

ciphers/rot13/rot13.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
package rot13
44

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

99
// rot13 is a special case, which is fixed the shift of 13, of the Caesar cipher
1010
func rot13(input string) string {
11-
return caesar.NewCaesar().Encrypt(input, 13)
11+
return caesar.Encrypt(input, 13)
1212
}

0 commit comments

Comments
 (0)