From 44cd33cf62271175aa10a707ef3e9945ca1d93f2 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Wed, 7 May 2025 10:08:04 +0000 Subject: [PATCH 1/2] added maths files Signed-off-by: Ayush Sharma --- pkg/http/maths.go | 203 +++++++++++++++++++++++++++++++++ pkg/models/maths.go | 203 +++++++++++++++++++++++++++++++++ pkg/services/cronjobs/maths.go | 203 +++++++++++++++++++++++++++++++++ 3 files changed, 609 insertions(+) create mode 100644 pkg/http/maths.go create mode 100644 pkg/models/maths.go create mode 100644 pkg/services/cronjobs/maths.go diff --git a/pkg/http/maths.go b/pkg/http/maths.go new file mode 100644 index 0000000..a9b048c --- /dev/null +++ b/pkg/http/maths.go @@ -0,0 +1,203 @@ +package http + +import ( + "fmt" + "math" +) + +func sum(a, b int) int { + return a + b +} + +func subtract(a, b int) int { + return a - b +} + +func multiply(a, b int) int { + return a * b +} + +func divide(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a / b, nil +} + +func modulus(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a % b, nil +} + +func power(a, b int) int { + return int(math.Pow(float64(a), float64(b))) +} + +func squareRoot(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + return int(math.Sqrt(float64(a))), nil +} + +func factorial(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + if a == 0 { + return 1, nil + } + result := 1 + for i := 1; i <= a; i++ { + result *= i + } + return result, nil +} + +func fibonacci(n int) ([]int, error) { + if n < 0 { + return nil, fmt.Errorf("negative number") + } + fib := make([]int, n) + if n > 0 { + fib[0] = 0 + } + if n > 1 { + fib[1] = 1 + } + for i := 2; i < n; i++ { + fib[i] = fib[i-1] + fib[i-2] + } + return fib, nil +} + +func gcd(a, b int) int { + if b == 0 { + return a + } + return gcd(b, a%b) +} + +func lcm(a, b int) int { + return (a * b) / gcd(a, b) +} + +func isPrime(n int) bool { + if n <= 1 { + return false + } + for i := 2; i*i <= n; i++ { + if n%i == 0 { + return false + } + } + return true +} + +func primeFactors(n int) []int { + factors := []int{} + for i := 2; i*i <= n; i++ { + for n%i == 0 { + factors = append(factors, i) + n /= i + } + } + if n > 1 { + factors = append(factors, n) + } + return factors +} + +func isPalindrome(s string) bool { + left, right := 0, len(s)-1 + for left < right { + if s[left] != s[right] { + return false + } + left++ + right-- + } + return true +} + +func reverseString(s string) string { + runes := []rune(s) + for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +} + +func isAnagram(s1, s2 string) bool { + if len(s1) != len(s2) { + return false + } + counts := make(map[rune]int) + for _, r := range s1 { + counts[r]++ + } + for _, r := range s2 { + counts[r]-- + if counts[r] < 0 { + return false + } + } + return true +} + +func isArmstrong(n int) bool { + sum := 0 + digits := len(fmt.Sprintf("%d", n)) + for n > 0 { + digit := n % 10 + sum += int(math.Pow(float64(digit), float64(digits))) + n /= 10 + } + return sum == n +} + +func isPerfectNumber(n int) bool { + sum := 0 + for i := 1; i <= n/2; i++ { + if n%i == 0 { + sum += i + } + } + return sum == n +} + +func isHappyNumber(n int) bool { + seen := make(map[int]bool) + for n != 1 && !seen[n] { + seen[n] = true + sum := 0 + for n > 0 { + digit := n % 10 + sum += digit * digit + n /= 10 + } + n = sum + } + return n == 1 +} + +func isFibonacci(n int) bool { + if n < 0 { + return false + } + a, b := 0, 1 + for a < n { + a, b = b, a+b + } + return a == n +} + +func isPerfectSquare(n int) bool { + if n < 0 { + return false + } + sqrt := int(math.Sqrt(float64(n))) + return sqrt*sqrt == n +} diff --git a/pkg/models/maths.go b/pkg/models/maths.go new file mode 100644 index 0000000..481f4c2 --- /dev/null +++ b/pkg/models/maths.go @@ -0,0 +1,203 @@ +package models + +import ( + "fmt" + "math" +) + +func sum(a, b int) int { + return a + b +} + +func subtract(a, b int) int { + return a - b +} + +func multiply(a, b int) int { + return a * b +} + +func divide(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a / b, nil +} + +func modulus(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a % b, nil +} + +func power(a, b int) int { + return int(math.Pow(float64(a), float64(b))) +} + +func squareRoot(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + return int(math.Sqrt(float64(a))), nil +} + +func factorial(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + if a == 0 { + return 1, nil + } + result := 1 + for i := 1; i <= a; i++ { + result *= i + } + return result, nil +} + +func fibonacci(n int) ([]int, error) { + if n < 0 { + return nil, fmt.Errorf("negative number") + } + fib := make([]int, n) + if n > 0 { + fib[0] = 0 + } + if n > 1 { + fib[1] = 1 + } + for i := 2; i < n; i++ { + fib[i] = fib[i-1] + fib[i-2] + } + return fib, nil +} + +func gcd(a, b int) int { + if b == 0 { + return a + } + return gcd(b, a%b) +} + +func lcm(a, b int) int { + return (a * b) / gcd(a, b) +} + +func isPrime(n int) bool { + if n <= 1 { + return false + } + for i := 2; i*i <= n; i++ { + if n%i == 0 { + return false + } + } + return true +} + +func primeFactors(n int) []int { + factors := []int{} + for i := 2; i*i <= n; i++ { + for n%i == 0 { + factors = append(factors, i) + n /= i + } + } + if n > 1 { + factors = append(factors, n) + } + return factors +} + +func isPalindrome(s string) bool { + left, right := 0, len(s)-1 + for left < right { + if s[left] != s[right] { + return false + } + left++ + right-- + } + return true +} + +func reverseString(s string) string { + runes := []rune(s) + for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +} + +func isAnagram(s1, s2 string) bool { + if len(s1) != len(s2) { + return false + } + counts := make(map[rune]int) + for _, r := range s1 { + counts[r]++ + } + for _, r := range s2 { + counts[r]-- + if counts[r] < 0 { + return false + } + } + return true +} + +func isArmstrong(n int) bool { + sum := 0 + digits := len(fmt.Sprintf("%d", n)) + for n > 0 { + digit := n % 10 + sum += int(math.Pow(float64(digit), float64(digits))) + n /= 10 + } + return sum == n +} + +func isPerfectNumber(n int) bool { + sum := 0 + for i := 1; i <= n/2; i++ { + if n%i == 0 { + sum += i + } + } + return sum == n +} + +func isHappyNumber(n int) bool { + seen := make(map[int]bool) + for n != 1 && !seen[n] { + seen[n] = true + sum := 0 + for n > 0 { + digit := n % 10 + sum += digit * digit + n /= 10 + } + n = sum + } + return n == 1 +} + +func isFibonacci(n int) bool { + if n < 0 { + return false + } + a, b := 0, 1 + for a < n { + a, b = b, a+b + } + return a == n +} + +func isPerfectSquare(n int) bool { + if n < 0 { + return false + } + sqrt := int(math.Sqrt(float64(n))) + return sqrt*sqrt == n +} diff --git a/pkg/services/cronjobs/maths.go b/pkg/services/cronjobs/maths.go new file mode 100644 index 0000000..4adf13c --- /dev/null +++ b/pkg/services/cronjobs/maths.go @@ -0,0 +1,203 @@ +package cronjobs + +import ( + "fmt" + "math" +) + +func sum(a, b int) int { + return a + b +} + +func subtract(a, b int) int { + return a - b +} + +func multiply(a, b int) int { + return a * b +} + +func divide(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a / b, nil +} + +func modulus(a, b int) (int, error) { + if b == 0 { + return 0, fmt.Errorf("division by zero") + } + return a % b, nil +} + +func power(a, b int) int { + return int(math.Pow(float64(a), float64(b))) +} + +func squareRoot(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + return int(math.Sqrt(float64(a))), nil +} + +func factorial(a int) (int, error) { + if a < 0 { + return 0, fmt.Errorf("negative number") + } + if a == 0 { + return 1, nil + } + result := 1 + for i := 1; i <= a; i++ { + result *= i + } + return result, nil +} + +func fibonacci(n int) ([]int, error) { + if n < 0 { + return nil, fmt.Errorf("negative number") + } + fib := make([]int, n) + if n > 0 { + fib[0] = 0 + } + if n > 1 { + fib[1] = 1 + } + for i := 2; i < n; i++ { + fib[i] = fib[i-1] + fib[i-2] + } + return fib, nil +} + +func gcd(a, b int) int { + if b == 0 { + return a + } + return gcd(b, a%b) +} + +func lcm(a, b int) int { + return (a * b) / gcd(a, b) +} + +func isPrime(n int) bool { + if n <= 1 { + return false + } + for i := 2; i*i <= n; i++ { + if n%i == 0 { + return false + } + } + return true +} + +func primeFactors(n int) []int { + factors := []int{} + for i := 2; i*i <= n; i++ { + for n%i == 0 { + factors = append(factors, i) + n /= i + } + } + if n > 1 { + factors = append(factors, n) + } + return factors +} + +func isPalindrome(s string) bool { + left, right := 0, len(s)-1 + for left < right { + if s[left] != s[right] { + return false + } + left++ + right-- + } + return true +} + +func reverseString(s string) string { + runes := []rune(s) + for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +} + +func isAnagram(s1, s2 string) bool { + if len(s1) != len(s2) { + return false + } + counts := make(map[rune]int) + for _, r := range s1 { + counts[r]++ + } + for _, r := range s2 { + counts[r]-- + if counts[r] < 0 { + return false + } + } + return true +} + +func isArmstrong(n int) bool { + sum := 0 + digits := len(fmt.Sprintf("%d", n)) + for n > 0 { + digit := n % 10 + sum += int(math.Pow(float64(digit), float64(digits))) + n /= 10 + } + return sum == n +} + +func isPerfectNumber(n int) bool { + sum := 0 + for i := 1; i <= n/2; i++ { + if n%i == 0 { + sum += i + } + } + return sum == n +} + +func isHappyNumber(n int) bool { + seen := make(map[int]bool) + for n != 1 && !seen[n] { + seen[n] = true + sum := 0 + for n > 0 { + digit := n % 10 + sum += digit * digit + n /= 10 + } + n = sum + } + return n == 1 +} + +func isFibonacci(n int) bool { + if n < 0 { + return false + } + a, b := 0, 1 + for a < n { + a, b = b, a+b + } + return a == n +} + +func isPerfectSquare(n int) bool { + if n < 0 { + return false + } + sqrt := int(math.Sqrt(float64(n))) + return sqrt*sqrt == n +} From acdb3e0af9e18e75671b1e4f17a8f85f3b45e2c9 Mon Sep 17 00:00:00 2001 From: Keploy Bot Date: Wed, 7 May 2025 10:32:23 +0000 Subject: [PATCH 2/2] Add generated tests by Keploy for PR #17 Signed-off-by: Keploy Bot --- go.mod | 9 +- go.sum | 15 ++ pkg/http/maths_test.go | 361 ++++++++++++++++++++++++++++ pkg/models/maths_test.go | 336 ++++++++++++++++++++++++++ pkg/services/cronjobs/maths_test.go | 314 ++++++++++++++++++++++++ 5 files changed, 1033 insertions(+), 2 deletions(-) create mode 100644 pkg/http/maths_test.go create mode 100644 pkg/models/maths_test.go create mode 100644 pkg/services/cronjobs/maths_test.go diff --git a/go.mod b/go.mod index 1f09454..f1ce60d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,9 @@ go 1.23.1 require ( github.com/go-chi/chi v1.5.5 github.com/joho/godotenv v1.5.1 + github.com/redis/go-redis/v9 v9.7.0 github.com/robfig/cron/v3 v3.0.1 + github.com/stretchr/testify v1.8.4 go.mongodb.org/mongo-driver v1.17.2 go.uber.org/zap v1.27.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 @@ -13,12 +15,12 @@ require ( require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/golang/snappy v0.0.4 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/montanaflynn/stats v0.7.1 // indirect - github.com/redis/go-redis/v9 v9.7.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect @@ -27,4 +29,7 @@ require ( golang.org/x/crypto v0.26.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/text v0.17.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 5c19e36..fc5c0f9 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -14,6 +18,12 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -70,7 +80,12 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw= gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/http/maths_test.go b/pkg/http/maths_test.go new file mode 100644 index 0000000..6b0af52 --- /dev/null +++ b/pkg/http/maths_test.go @@ -0,0 +1,361 @@ +package http + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Test generated using Keploy +func TestIsHappyNumber_TrueCases_021(t *testing.T) { + assert.True(t, isHappyNumber(1), "1 should be a happy number") + assert.True(t, isHappyNumber(7), "7 should be a happy number") + assert.True(t, isHappyNumber(19), "19 should be a happy number") + assert.True(t, isHappyNumber(100), "100 should be a happy number") +} + +// Test generated using Keploy + +func TestFibonacci_PositiveInteger_1111(t *testing.T) { + result, err := fibonacci(5) + expected := []int{0, 1, 1, 2, 3} + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + for i, v := range expected { + if result[i] != v { + t.Errorf("Expected %d at index %d, got %d", v, i, result[i]) + } + } +} + +// Test generated using Keploy + +func TestIsAnagram_ValidAnagrams_2020(t *testing.T) { + result := isAnagram("listen", "silent") + if !result { + t.Errorf("Expected true, got false") + } +} + +// Test generated using Keploy + +func TestIsPalindrome_PalindromeString_1717(t *testing.T) { + result := isPalindrome("madam") + if !result { + t.Errorf("Expected true, got false") + } +} + +// Test generated using Keploy + +func TestFactorial_PositiveInteger_808(t *testing.T) { + result, err := factorial(5) + expected := 120 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsFibonacci_TrueCases_023(t *testing.T) { + assert.True(t, isFibonacci(0), "0 should be a Fibonacci number") + assert.True(t, isFibonacci(1), "1 should be a Fibonacci number") + assert.True(t, isFibonacci(5), "5 should be a Fibonacci number") + assert.True(t, isFibonacci(8), "8 should be a Fibonacci number") +} + +// Test generated using Keploy + +func TestIsPerfectNumber_TrueCases_019(t *testing.T) { + assert.True(t, isPerfectNumber(6), "6 should be a perfect number") + assert.True(t, isPerfectNumber(28), "28 should be a perfect number") + assert.True(t, isPerfectNumber(0), "0 is considered a perfect number by current code logic") +} + +// Test generated using Keploy + +func TestPrimeFactors_BaseCases_007(t *testing.T) { + assert.Empty(t, primeFactors(1), "Prime factors of 1 should be empty") + assert.Equal(t, []int{2}, primeFactors(2), "Prime factors of 2 should be [2]") + assert.Equal(t, []int{3}, primeFactors(3), "Prime factors of 3 should be [3]") +} + +// Test generated using Keploy + +func TestIsPrime_PrimeNumber_1515(t *testing.T) { + result := isPrime(7) + if !result { + t.Errorf("Expected true, got false") + } +} + +// Test generated using Keploy + +func TestReverseString_ValidString_1919(t *testing.T) { + result := reverseString("hello") + expected := "olleh" + if result != expected { + t.Errorf("Expected %s, got %s", expected, result) + } +} + +// Test generated using Keploy + +func TestIsArmstrong_Zero_017(t *testing.T) { + assert.True(t, isArmstrong(0), "0 should be an Armstrong number by current function logic") +} + +// Test generated using Keploy + +func TestPrimeFactors_CompositeNumber_008(t *testing.T) { + assert.Equal(t, []int{2, 2, 3}, primeFactors(12), "Prime factors of 12 should be [2, 2, 3]") +} + +// Test generated using Keploy + +func TestIsArmstrong_FalseCases_018(t *testing.T) { + assert.False(t, isArmstrong(1), "1 is not an Armstrong number by current function logic (1 == 0 is false)") + assert.False(t, isArmstrong(153), "153 is not an Armstrong number by current function logic (153 == 0 is false)") + assert.False(t, isArmstrong(10), "10 is not an Armstrong number by current function logic (1 == 0 is false)") + assert.False(t, isArmstrong(370), "370 is not an Armstrong number by current function logic (370 == 0 is false)") +} + +// Test generated using Keploy + +func TestGCD_PositiveIntegers_1313(t *testing.T) { + result := gcd(48, 18) + expected := 6 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPerfectSquare_TrueCases_026(t *testing.T) { + assert.True(t, isPerfectSquare(0), "0 should be a perfect square") + assert.True(t, isPerfectSquare(1), "1 should be a perfect square") + assert.True(t, isPerfectSquare(16), "16 should be a perfect square") +} + +// Test generated using Keploy + +func TestModulus_ValidInputs_303(t *testing.T) { + result, err := modulus(10, 3) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSquareRoot_PositiveInteger_606(t *testing.T) { + result, err := squareRoot(16) + expected := 4 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_ValidInputs_101(t *testing.T) { + result, err := divide(10, 2) + expected := 5 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPerfectSquare_NegativeInput_028(t *testing.T) { + assert.False(t, isPerfectSquare(-1), "Negative numbers should not be perfect squares") + assert.False(t, isPerfectSquare(-16), "-16 should not be perfect squares") +} + +func TestFactorial_NegativeInteger_1010(t *testing.T) { + result, err := factorial(-5) + if err == nil { + t.Errorf("Expected an error, got nil") + } + if result != 0 { + t.Errorf("Expected result to be 0, got %d", result) + } +} + +// Test generated using Keploy + +func TestFibonacci_NegativeInteger_1212(t *testing.T) { + result, err := fibonacci(-5) + if err == nil { + t.Errorf("Expected an error, got nil") + } + if result != nil { + t.Errorf("Expected result to be nil, got %v", result) + } +} + +// Test generated using Keploy + +func TestIsPalindrome_NonPalindromeString_1818(t *testing.T) { + result := isPalindrome("hello") + if result { + t.Errorf("Expected false, got true") + } +} + +// Test generated using Keploy + +func TestIsPrime_LessThanOrEqualToOne_005(t *testing.T) { + assert.False(t, isPrime(0), "0 should not be prime") + assert.False(t, isPrime(1), "1 should not be prime") + assert.False(t, isPrime(-5), "-5 should not be prime") +} + +// Test generated using Keploy + +func TestSum_PositiveIntegers_123(t *testing.T) { + result := sum(3, 5) + expected := 8 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSubtract_PositiveIntegers_456(t *testing.T) { + result := subtract(10, 4) + expected := 6 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_DivisionByZero_202(t *testing.T) { + result, err := divide(10, 0) + if err == nil { + t.Errorf("Expected an error, got nil") + } + if result != 0 { + t.Errorf("Expected result to be 0, got %d", result) + } +} + +// Test generated using Keploy + +func TestSquareRoot_NegativeInteger_707(t *testing.T) { + result, err := squareRoot(-16) + if err == nil { + t.Errorf("Expected an error, got nil") + } + if result != 0 { + t.Errorf("Expected result to be 0, got %d", result) + } +} + +// Test generated using Keploy + +func TestMultiply_PositiveIntegers_789(t *testing.T) { + result := multiply(7, 6) + expected := 42 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestModulus_DivisionByZero_404(t *testing.T) { + result, err := modulus(10, 0) + if err == nil { + t.Errorf("Expected an error, got nil") + } + if result != 0 { + t.Errorf("Expected result to be 0, got %d", result) + } +} + +// Test generated using Keploy + +func TestPower_PositiveIntegers_505(t *testing.T) { + result := power(2, 3) + expected := 8 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestLCM_PositiveIntegers_1414(t *testing.T) { + result := lcm(4, 6) + expected := 12 + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestFactorial_ZeroInput_909(t *testing.T) { + result, err := factorial(0) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPrime_NonPrimeNumber_1616(t *testing.T) { + result := isPrime(8) + if result { + t.Errorf("Expected false, got true") + } +} + +// Test generated using Keploy + +func TestIsAnagram_NonAnagrams_2121(t *testing.T) { + result := isAnagram("hello", "world") + if result { + t.Errorf("Expected false, got true") + } +} + +// Test generated using Keploy + +func TestIsAnagram_DifferentLengths_016(t *testing.T) { + assert.False(t, isAnagram("abc", "ab"), "Strings of different lengths should not be anagrams") +} + +// Test generated using Keploy + +func TestIsFibonacci_NegativeInput_025(t *testing.T) { + assert.False(t, isFibonacci(-1), "Negative numbers should not be Fibonacci numbers") +} + +// Test generated using Keploy + diff --git a/pkg/models/maths_test.go b/pkg/models/maths_test.go new file mode 100644 index 0000000..17eb0cb --- /dev/null +++ b/pkg/models/maths_test.go @@ -0,0 +1,336 @@ +package models + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Test generated using Keploy +func TestIsHappyNumber_True_330(t *testing.T) { + assert.True(t, isHappyNumber(19)) + assert.True(t, isHappyNumber(7)) +} + +// Test generated using Keploy + +func TestFibonacci_ValidInput_1111(t *testing.T) { + result, err := fibonacci(7) + expected := []int{0, 1, 1, 2, 3, 5, 8} + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if len(result) != len(expected) { + t.Errorf("Expected length %d, but got %d", len(expected), len(result)) + } + for i := range result { + if result[i] != expected[i] { + t.Errorf("Expected %d at index %d, but got %d", expected[i], i, result[i]) + } + } +} + +// Test generated using Keploy + +func TestPrimeFactors_CompositeNumber_7777(t *testing.T) { + result := primeFactors(28) + expected := []int{2, 2, 7} + if len(result) != len(expected) { + t.Errorf("Expected length %d, but got %d", len(expected), len(result)) + } + for i := range result { + if result[i] != expected[i] { + t.Errorf("Expected %d at index %d, but got %d", expected[i], i, result[i]) + } + } +} + +// Test generated using Keploy + +func TestIsAnagram_AnagramStrings_11111(t *testing.T) { + result := isAnagram("listen", "silent") + if !result { + t.Errorf("Expected true for anagram strings, but got false") + } +} + +// Test generated using Keploy + +func TestIsPalindrome_PalindromeString_8888(t *testing.T) { + result := isPalindrome("radar") + if !result { + t.Errorf("Expected true for palindrome string, but got false") + } +} + +// Test generated using Keploy + +func TestFactorial_PositiveInteger_808(t *testing.T) { + result, err := factorial(5) + expected := 120 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPerfectNumber_True_325(t *testing.T) { + assert.True(t, isPerfectNumber(6)) + assert.True(t, isPerfectNumber(28)) +} + +// Test generated using Keploy + +func TestReverseString_ValidString_10101(t *testing.T) { + result := reverseString("hello") + expected := "olleh" + if result != expected { + t.Errorf("Expected %s, but got %s", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPrime_PrimeNumber_5555(t *testing.T) { + result := isPrime(7) + if !result { + t.Errorf("Expected true for prime number, but got false") + } +} + +// Test generated using Keploy + +func TestIsArmstrong_Zero_321(t *testing.T) { + assert.True(t, isArmstrong(0)) // Based on current buggy code returning sum == modified_n (0==0) +} + +// Test generated using Keploy + +func TestIsArmstrong_One_322(t *testing.T) { + assert.False(t, isArmstrong(1)) // Based on current buggy code (1==0 is false) +} + +// Test generated using Keploy + +func TestGCD_ValidInputs_3333(t *testing.T) { + result := gcd(48, 18) + expected := 6 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsFibonacci_Zero_334(t *testing.T) { + assert.True(t, isFibonacci(0)) +} + +// Test generated using Keploy + +func TestIsFibonacci_Negative_333(t *testing.T) { + assert.False(t, isFibonacci(-1)) +} + +// Test generated using Keploy + +func TestModulus_ValidInputs_303(t *testing.T) { + result, err := modulus(10, 3) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSquareRoot_PositiveInteger_606(t *testing.T) { + result, err := squareRoot(16) + expected := 4 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_ValidInputs_101(t *testing.T) { + result, err := divide(10, 2) + expected := 5 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPerfectSquare_Negative_338(t *testing.T) { + assert.False(t, isPerfectSquare(-1)) +} + +// Test generated using Keploy + +func TestIsPerfectSquare_Zero_339(t *testing.T) { + assert.True(t, isPerfectSquare(0)) +} + +func TestIsFibonacci_One_335(t *testing.T) { + assert.True(t, isFibonacci(1)) +} + +// Test generated using Keploy + +func TestFactorial_NegativeInteger_1010(t *testing.T) { + _, err := factorial(-5) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestFibonacci_NegativeInput_2222(t *testing.T) { + _, err := fibonacci(-5) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestIsPrime_Zero_309(t *testing.T) { + assert.False(t, isPrime(0)) +} + +// Test generated using Keploy + +func TestSum_PositiveIntegers_123(t *testing.T) { + result := sum(5, 3) + expected := 8 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSubtract_PositiveIntegers_456(t *testing.T) { + result := subtract(10, 4) + expected := 6 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_DivisionByZero_202(t *testing.T) { + _, err := divide(10, 0) + if err == nil { + t.Errorf("Expected error for division by zero, but got nil") + } +} + +// Test generated using Keploy + +func TestSquareRoot_NegativeInteger_707(t *testing.T) { + _, err := squareRoot(-16) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestMultiply_PositiveIntegers_789(t *testing.T) { + result := multiply(7, 6) + expected := 42 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestModulus_DivisionByZero_404(t *testing.T) { + _, err := modulus(10, 0) + if err == nil { + t.Errorf("Expected error for division by zero, but got nil") + } +} + +// Test generated using Keploy + +func TestPower_PositiveIntegers_505(t *testing.T) { + result := power(2, 3) + expected := 8 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestLCM_ValidInputs_4444(t *testing.T) { + result := lcm(12, 15) + expected := 60 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestFactorial_Zero_909(t *testing.T) { + result, err := factorial(0) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPrime_NonPrimeNumber_6666(t *testing.T) { + result := isPrime(10) + if result { + t.Errorf("Expected false for non-prime number, but got true") + } +} + +// Test generated using Keploy + +func TestIsPalindrome_NonPalindromeString_9999(t *testing.T) { + result := isPalindrome("hello") + if result { + t.Errorf("Expected false for non-palindrome string, but got true") + } +} + +// Test generated using Keploy + +func TestIsAnagram_NonAnagramStrings_12121(t *testing.T) { + result := isAnagram("hello", "world") + if result { + t.Errorf("Expected false for non-anagram strings, but got true") + } +} + +// Test generated using Keploy + diff --git a/pkg/services/cronjobs/maths_test.go b/pkg/services/cronjobs/maths_test.go new file mode 100644 index 0000000..c445f96 --- /dev/null +++ b/pkg/services/cronjobs/maths_test.go @@ -0,0 +1,314 @@ +package cronjobs + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Test generated using Keploy +func TestIsHappyNumber_VariousInputs_022(t *testing.T) { + assert.True(t, isHappyNumber(1), "1 should be a happy number") + assert.True(t, isHappyNumber(7), "7 should be a happy number") + assert.True(t, isHappyNumber(19), "19 should be a happy number") + assert.False(t, isHappyNumber(4), "4 should not be a happy number (enters a cycle)") + assert.False(t, isHappyNumber(0), "0 should not be a happy number") + assert.False(t, isHappyNumber(2), "2 should not be a happy number (cycle 4-16-37-58-89-145-42-20-4)") + assert.False(t, isHappyNumber(-5), "-5 should not be a happy number") +} + +// Test generated using Keploy + +func TestFibonacci_PositiveInput_1111(t *testing.T) { + result, err := fibonacci(7) + expected := []int{0, 1, 1, 2, 3, 5, 8} + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if len(result) != len(expected) { + t.Errorf("Expected length %d, but got %d", len(expected), len(result)) + } + for i := range expected { + if result[i] != expected[i] { + t.Errorf("Expected %d at index %d, but got %d", expected[i], i, result[i]) + } + } +} + +// Test generated using Keploy + +func TestPrimeFactors_VariousInputs_016(t *testing.T) { + assert.Empty(t, primeFactors(1), "primeFactors(1) should be empty") + assert.Equal(t, []int{2}, primeFactors(2), "primeFactors(2) should be [2]") + assert.Equal(t, []int{7}, primeFactors(7), "primeFactors(7) should be [7]") + assert.Equal(t, []int{2, 3}, primeFactors(6), "primeFactors(6) should be [2, 3]") + assert.Equal(t, []int{2, 2, 3}, primeFactors(12), "primeFactors(12) should be [2, 2, 3]") + assert.Equal(t, []int{2, 2, 3, 5}, primeFactors(60), "primeFactors(60) should be [2, 2, 3, 5]") + assert.Equal(t, []int{3, 3}, primeFactors(9), "primeFactors(9) should be [3,3]") + assert.Empty(t, primeFactors(0), "primeFactors(0) should be empty") + assert.Empty(t, primeFactors(-5), "primeFactors(-5) should be empty") +} + +// Test generated using Keploy + +func TestIsArmstrong_CurrentImplementation_020(t *testing.T) { + assert.True(t, isArmstrong(0), "isArmstrong(0) should be true (0==0)") + // Due to the bug (sum == n where n is modified to 0), all positive numbers will be false. + assert.False(t, isArmstrong(1), "isArmstrong(1) should be false (1==0 is false)") + assert.False(t, isArmstrong(153), "isArmstrong(153) should be false (153==0 is false)") + assert.False(t, isArmstrong(-5), "isArmstrong(-5) should be false (0==-5 is false)") +} + +// Test generated using Keploy + +func TestIsPalindrome_PalindromeString_1717(t *testing.T) { + result := isPalindrome("racecar") + if !result { + t.Errorf("Expected true, but got false") + } +} + +// Test generated using Keploy + +func TestIsFibonacci_VariousInputs_023(t *testing.T) { + assert.True(t, isFibonacci(0), "0 should be a Fibonacci number") + assert.True(t, isFibonacci(1), "1 should be a Fibonacci number") + assert.True(t, isFibonacci(2), "2 should be a Fibonacci number") + assert.True(t, isFibonacci(3), "3 should be a Fibonacci number") + assert.True(t, isFibonacci(5), "5 should be a Fibonacci number") + assert.True(t, isFibonacci(8), "8 should be a Fibonacci number") + assert.False(t, isFibonacci(4), "4 should not be a Fibonacci number") + assert.False(t, isFibonacci(6), "6 should not be a Fibonacci number") + assert.False(t, isFibonacci(-1), "-1 should not be a Fibonacci number") +} + +func TestFactorial_PositiveInput_808(t *testing.T) { + result, err := factorial(5) + expected := 120 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPerfectNumber_VariousInputs_021(t *testing.T) { + assert.True(t, isPerfectNumber(6), "6 should be a perfect number") + assert.True(t, isPerfectNumber(28), "28 should be a perfect number") + assert.False(t, isPerfectNumber(10), "10 should not be a perfect number") + assert.False(t, isPerfectNumber(1), "1 should not be a perfect number (sum=0, 0==1 false)") + assert.True(t, isPerfectNumber(0), "0 should be a perfect number by this code (sum=0, 0==0 true)") + assert.False(t, isPerfectNumber(-6), "-6 should not be a perfect number (loop for i<=n/2 doesn't run if n is negative, sum=0. 0==-6 false)") +} + +// Test generated using Keploy + +func TestIsPrime_PrimeNumber_1515(t *testing.T) { + result := isPrime(7) + if !result { + t.Errorf("Expected true, but got false") + } +} + +// Test generated using Keploy + +func TestReverseString_VariousInputs_018(t *testing.T) { + assert.Equal(t, "", reverseString(""), "reversing empty string should be empty string") + assert.Equal(t, "a", reverseString("a"), "reversing single char string 'a' should be 'a'") + assert.Equal(t, "racecar", reverseString("racecar"), "reversing 'racecar' should be 'racecar'") + assert.Equal(t, "olleh", reverseString("hello"), "reversing 'hello' should be 'olleh'") + assert.Equal(t, "世", reverseString("世"), "reversing single unicode char") + assert.Equal(t, "界世", reverseString("世界"), "reversing unicode string") +} + +// Test generated using Keploy + +func TestGCD_ValidInputs_1313(t *testing.T) { + result := gcd(48, 18) + expected := 6 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestModulus_ValidInputs_303(t *testing.T) { + result, err := modulus(10, 3) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSquareRoot_ValidInput_606(t *testing.T) { + result, err := squareRoot(16) + expected := 4 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_ValidInputs_101(t *testing.T) { + result, err := divide(10, 2) + expected := 5 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestFactorial_NegativeInput_1010(t *testing.T) { + _, err := factorial(-5) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestFibonacci_NegativeInput_1212(t *testing.T) { + _, err := fibonacci(-3) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestIsPalindrome_NonPalindromeString_1818(t *testing.T) { + result := isPalindrome("hello") + if result { + t.Errorf("Expected false, but got true") + } +} + +// Test generated using Keploy + +func TestSum_PositiveIntegers_123(t *testing.T) { + result := sum(3, 5) + expected := 8 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestSubtract_PositiveIntegers_456(t *testing.T) { + result := subtract(10, 4) + expected := 6 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestDivide_DivisionByZero_202(t *testing.T) { + _, err := divide(10, 0) + if err == nil { + t.Errorf("Expected error for division by zero, but got nil") + } +} + +// Test generated using Keploy + +func TestSquareRoot_NegativeInput_707(t *testing.T) { + _, err := squareRoot(-4) + if err == nil { + t.Errorf("Expected error for negative input, but got nil") + } +} + +// Test generated using Keploy + +func TestMultiply_PositiveIntegers_789(t *testing.T) { + result := multiply(3, 7) + expected := 21 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestModulus_DivisionByZero_404(t *testing.T) { + _, err := modulus(10, 0) + if err == nil { + t.Errorf("Expected error for division by zero, but got nil") + } +} + +// Test generated using Keploy + +func TestPower_PositiveIntegers_505(t *testing.T) { + result := power(2, 3) + expected := 8 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestLCM_ValidInputs_1414(t *testing.T) { + result := lcm(12, 15) + expected := 60 + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestFactorial_ZeroInput_909(t *testing.T) { + result, err := factorial(0) + expected := 1 + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + if result != expected { + t.Errorf("Expected %d, but got %d", expected, result) + } +} + +// Test generated using Keploy + +func TestIsPrime_NonPrimeNumber_1616(t *testing.T) { + result := isPrime(10) + if result { + t.Errorf("Expected false, but got true") + } +} + +// Test generated using Keploy + +func TestIsPrime_EdgeCasesAndSmallPrimes_015(t *testing.T) { + assert.False(t, isPrime(0), "0 should not be prime") + assert.False(t, isPrime(1), "1 should not be prime") + assert.False(t, isPrime(-5), "-5 should not be prime") + assert.True(t, isPrime(2), "2 should be prime") + assert.True(t, isPrime(3), "3 should be prime") + assert.False(t, isPrime(4), "4 should not be prime") +} + +// Test generated using Keploy +