Skip to content

Commit

Permalink
prettier: code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
rulanugrh committed Mar 11, 2024
1 parent 8411c32 commit f5b7f08
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 273 deletions.
28 changes: 14 additions & 14 deletions basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import (
)

func TestMain(t *testing.M) {
t.Run()
t.Run()
}

func TestFactorial(t *testing.T) {
num := Factorial(5)
num := Factorial(5)

assert.Equal(t, 120, num)
assert.Equal(t, 120, num)
}

func TestRecursive(t *testing.T) {
num := Recursive(7)
num := Recursive(7)

assert.Equal(t, 112, num)
assert.Equal(t, 112, num)
}

func TestFizzBuzz(t *testing.T) {
a := FizzBuzz(5)
b := FizzBuzz(3)
c := FizzBuzz(15)
d := FizzBuzz(19)

assert.Equal(t, "Fizz", b)
assert.Equal(t, "Buzz", a)
assert.Equal(t, "FizzBuzz", c)
assert.Equal(t, 19, d)
a := FizzBuzz(5)
b := FizzBuzz(3)
c := FizzBuzz(15)
d := FizzBuzz(19)

assert.Equal(t, "Fizz", b)
assert.Equal(t, "Buzz", a)
assert.Equal(t, "FizzBuzz", c)
assert.Equal(t, 19, d)
}
10 changes: 5 additions & 5 deletions basic/factorial.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package basic

func Factorial(n int) int {
if n == 1 {
return 1
} else {
return n * Factorial(n - 1)
}
if n == 1 {
return 1
} else {
return n * Factorial(n-1)
}
}
18 changes: 9 additions & 9 deletions basic/fizzbuzz.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package basic

func FizzBuzz(num int) any {
if num % 3 == 0 && num % 5 == 0 {
return "FizzBuzz"
} else if num % 3 == 0 {
return "Fizz"
} else if num % 5 == 0 {
return "Buzz"
} else {
return num
}
if num%3 == 0 && num%5 == 0 {
return "FizzBuzz"
} else if num%3 == 0 {
return "Fizz"
} else if num%5 == 0 {
return "Buzz"
} else {
return num
}
}
14 changes: 7 additions & 7 deletions basic/recursive.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package basic

func Recursive(n int) int {
if n < 100 {
return Recursive(n + n)
} else if n >= 100 {
return n
} else {
return 0
}
if n < 100 {
return Recursive(n + n)
} else if n >= 100 {
return n
} else {
return 0
}
}
24 changes: 12 additions & 12 deletions data-structure/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package data
import "strings"

type Array struct {
Elems []string
Elems []string
}

func (a *Array) InsertArray(data string) {
if data == ""{
println("data null")
}
if data == "" {
println("data null")
}

a.Elems = append(a.Elems, data)
a.Elems = append(a.Elems, data)
}

func (a *Array) DeletedArray(index int) string {
if len(a.Elems) == 0 {
return "sorry data is null"
}
if len(a.Elems) == 0 {
return "sorry data is null"
}

a.Elems = append(a.Elems[:index], a.Elems[index+1:]...)
a.Elems = append(a.Elems[:index], a.Elems[index+1:]...)

return "success deleted"
return "success deleted"
}

func (a *Array) JoinArray(sep string) string {
data := strings.Join(a.Elems, sep)
return data
data := strings.Join(a.Elems, sep)
return data
}
76 changes: 38 additions & 38 deletions data-structure/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@ import (
)

func TestMain(t *testing.M) {
println("running test data structure")
println("running test data structure")

t.Run()
t.Run()

println("running test done")
println("running test done")
}

func TestArray(t *testing.T) {
arr := Array{}
arr.InsertArray("ruls")
arr.InsertArray("kyoo")
arr := Array{}
arr.InsertArray("ruls")
arr.InsertArray("kyoo")

value := arr.JoinArray(", ")
assert.Equal(t, "ruls, kyoo", value)
value := arr.JoinArray(", ")
assert.Equal(t, "ruls, kyoo", value)
}

func TestDeleteArray(t *testing.T) {
arr := Array{}
arr.InsertArray("ruls")
arr.InsertArray("kyoo")
arr := Array{}
arr.InsertArray("ruls")
arr.InsertArray("kyoo")

value := arr.DeletedArray(1)
assert.Equal(t, "success deleted", value)
value := arr.DeletedArray(1)
assert.Equal(t, "success deleted", value)
}

func TestInsertStack(t *testing.T) {
arr := Stack{}
arr.PushStack("ruls")
arr.PushStack("kyoo")
arr := Stack{}
arr.PushStack("ruls")
arr.PushStack("kyoo")

value := arr.JoinStack(", ")
assert.Equal(t, "ruls, kyoo", value)
value := arr.JoinStack(", ")
assert.Equal(t, "ruls, kyoo", value)
}

func TestDeleteStack(t *testing.T) {
arr := Stack{}
arr.PushStack("ruls")
arr.PushStack("kyoo")
arr.PushStack("ryoo")
arr := Stack{}
arr.PushStack("ruls")
arr.PushStack("kyoo")
arr.PushStack("ryoo")

value := arr.TopStack()
asserts := []string{"ruls", "kyoo"}
value := arr.TopStack()
asserts := []string{"ruls", "kyoo"}

assert.Equal(t, asserts, value)
assert.Equal(t, asserts, value)
}

func TestDeleteByIndexStack(t *testing.T) {
arr := Stack{}
arr.PushStack("yooo")
arr.PushStack("kyoo")
arr.PushStack("ryoo")

arr.PopStack(1)
value := arr.JoinStack(", ")
assert.Equal(t, "yooo, ryoo", value)
arr := Stack{}
arr.PushStack("yooo")
arr.PushStack("kyoo")
arr.PushStack("ryoo")

arr.PopStack(1)
value := arr.JoinStack(", ")
assert.Equal(t, "yooo, ryoo", value)
}

func TestQueues(t *testing.T) {
arr := Queues{}
arr.InsertQueues("araa")
arr.InsertQueues("khairunnisa")
arr := Queues{}
arr.InsertQueues("araa")
arr.InsertQueues("khairunnisa")

value := arr.DeleteQueues()
assert.Equal(t, "araa", value)
value := arr.DeleteQueues()
assert.Equal(t, "araa", value)
}
32 changes: 16 additions & 16 deletions data-structure/queues.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package data

type Queues struct {
Elems []string
Elems []string
}

func (q *Queues) InsertQueues(elem string){
if elem == "" {
println("data null")
}
func (q *Queues) InsertQueues(elem string) {
if elem == "" {
println("data null")
}

q.Elems = append(q.Elems, elem)
q.Elems = append(q.Elems, elem)
}

func (q *Queues) DeleteQueues() string {
if len(q.Elems) == 0 {
println("Null Data")
}
if len(q.Elems) == 0 {
println("Null Data")
}

element := q.Elems[0]
if len(q.Elems) == 1{
q.Elems = nil
return element
}
element := q.Elems[0]
if len(q.Elems) == 1 {
q.Elems = nil
return element
}

q.Elems = q.Elems[1:]
return element
q.Elems = q.Elems[1:]
return element
}
26 changes: 13 additions & 13 deletions data-structure/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import (

// stack style LIFO
type Stack struct {
Elems []string
Elems []string
}

func (s *Stack) PushStack(data string) {
if data == "" {
println("data null")
}
if data == "" {
println("data null")
}

s.Elems = append(s.Elems, data)
s.Elems = append(s.Elems, data)
}

func (s *Stack) TopStack() []string {
for len(s.Elems) > 0 {
n := len(s.Elems) - 1
s.Elems = s.Elems[:n]
for len(s.Elems) > 0 {
n := len(s.Elems) - 1
s.Elems = s.Elems[:n]

return s.Elems
return s.Elems

}
}

return nil
return nil
}

func (s *Stack) PopStack(index int) {
s.Elems = append(s.Elems[:index], s.Elems[index+1:]...)
s.Elems = append(s.Elems[:index], s.Elems[index+1:]...)
}

func (s *Stack) JoinStack(sep string) string {
return strings.Join(s.Elems, sep)
return strings.Join(s.Elems, sep)
}
28 changes: 14 additions & 14 deletions search/binary.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package search

func BinarySearch(data []int, item int) string {
var low = 0
var low = 0

var high = len(data) - 1
var high = len(data) - 1

for low <= high {
var mid = low + high
var guess = data[mid]
for low <= high {
var mid = low + high
var guess = data[mid]

if guess == item {
return "Data found"
} else if guess > item {
high = mid - 1
} else {
low = mid + 1
}
}
if guess == item {
return "Data found"
} else if guess > item {
high = mid - 1
} else {
low = mid + 1
}
}

return "Data not found"
return "Data not found"
}
12 changes: 6 additions & 6 deletions search/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

func TestBinarySearch(t *testing.T) {
data := []int{1, 2, 3, 7, 20, 22}
result := BinarySearch(data, 7)
data := []int{1, 2, 3, 7, 20, 22}
result := BinarySearch(data, 7)

assert.Equal(t, "Data found", result)
assert.Equal(t, "Data found", result)
}

func TestNotFoundBinarySearch(t *testing.T) {
data := []int{1, 2, 3, 7, 20, 22}
result := BinarySearch(data, 11)
data := []int{1, 2, 3, 7, 20, 22}
result := BinarySearch(data, 11)

assert.NotEqual(t, "Data found", result)
assert.NotEqual(t, "Data found", result)
}
Loading

0 comments on commit f5b7f08

Please sign in to comment.