Skip to content

Commit

Permalink
feat(cipher/rot13): add fuzz test to rot13 cipher (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcaci authored Oct 25, 2022
1 parent 51c9532 commit 213cfa6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
84 changes: 51 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
10. [`Sqrt`](./math/binary/sqrt.go#L16): No description provided.
11. [`XorSearchMissingNumber`](./math/binary/xorsearch.go#L11): XorSearchMissingNumber This function finds a missing number in a sequence

---
</details><details>
<summary> <strong> cache </strong> </summary>

---

##### Functions:

1. [`NewLRU`](./cache/lru.go#L20): NewLRU represent initiate lru cache with capacity

---
##### Types

1. [`LRU`](./cache/lru.go#L12): No description provided.


---
</details><details>
<summary> <strong> caesar </strong> </summary>
Expand All @@ -92,6 +108,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.

1. [`Decrypt`](./cipher/caesar/caesar.go#L27): Decrypt decrypts by left shift of "key" each character of "input"
2. [`Encrypt`](./cipher/caesar/caesar.go#L6): Encrypt encrypts by right shift of "key" each character of "input"
3. [`FuzzCaesar`](./cipher/caesar/caesar_test.go#L158): No description provided.

---
</details><details>
Expand Down Expand Up @@ -217,11 +234,11 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
7. [`EditDistanceRecursive`](./dynamic/editdistance.go#L10): EditDistanceRecursive is a naive implementation with exponential time complexity.
8. [`IsSubsetSum`](./dynamic/subsetsum.go#L14): No description provided.
9. [`Knapsack`](./dynamic/knapsack.go#L17): Knapsack solves knapsack problem return maxProfit
10. [`LongestCommonSubsequence`](./dynamic/longestcommonsubsequence.go#L8): LongestCommonSubsequence function
10. [`LongestCommonSubsequence`](./dynamic/longestcommonsubsequence.go#L12): LongestCommonSubsequence function
11. [`LongestIncreasingSubsequence`](./dynamic/longestincreasingsubsequence.go#L9): LongestIncreasingSubsequence returns the longest increasing subsequence where all elements of the subsequence are sorted in increasing order
12. [`LongestIncreasingSubsequenceGreedy`](./dynamic/longestincreasingsubsequencegreedy.go#L9): LongestIncreasingSubsequenceGreedy is a function to find the longest increasing subsequence in a given array using a greedy approach. The dynamic programming approach is implemented alongside this one. Worst Case Time Complexity: O(nlogn) Auxiliary Space: O(n), where n is the length of the array(slice). Reference: https://www.geeksforgeeks.org/construction-of-longest-monotonically-increasing-subsequence-n-log-n/
13. [`LpsDp`](./dynamic/longestpalindromicsubsequence.go#L21): LpsDp function
14. [`LpsRec`](./dynamic/longestpalindromicsubsequence.go#L7): LpsRec function
13. [`LpsDp`](./dynamic/longestpalindromicsubsequence.go#L25): LpsDp function
14. [`LpsRec`](./dynamic/longestpalindromicsubsequence.go#L20): LpsRec function
15. [`MatrixChainDp`](./dynamic/matrixmultiplication.go#L24): MatrixChainDp function
16. [`MatrixChainRec`](./dynamic/matrixmultiplication.go#L10): MatrixChainRec function
17. [`Max`](./dynamic/knapsack.go#L11): Max function - possible duplicate
Expand Down Expand Up @@ -459,7 +476,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.

1. [`JosephusProblem`](./structure/linkedlist/cyclic.go#L120): https://en.wikipedia.org/wiki/Josephus_problem This is a struct-based solution for Josephus problem.
2. [`NewCyclic`](./structure/linkedlist/cyclic.go#L12): Create new list.
3. [`NewDoubly`](./structure/linkedlist/doubly.go#L22): No description provided.
3. [`NewDoubly`](./structure/linkedlist/doubly.go#L31): No description provided.
4. [`NewNode`](./structure/linkedlist/shared.go#L12): Create new node.
5. [`NewSingly`](./structure/linkedlist/singlylinkedlist.go#L19): NewSingly returns a new instance of a linked list

Expand Down Expand Up @@ -504,15 +521,18 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
4. [`DefaultPolynomial`](./math/pollard.go#L16): DefaultPolynomial is the commonly used polynomial g(x) = (x^2 + 1) mod n
5. [`FindKthMax`](./math/kthnumber.go#L11): FindKthMax returns the kth large element given an integer slice with nil `error` if found and returns -1 with `error` `search.ErrNotFound` if not found. NOTE: The `nums` slice gets mutated in the process.
6. [`FindKthMin`](./math/kthnumber.go#L19): FindKthMin returns kth small element given an integer slice with nil `error` if found and returns -1 with `error` `search.ErrNotFound` if not found. NOTE: The `nums` slice gets mutated in the process.
7. [`IsPowOfTwoUseLog`](./math/checkisnumberpoweroftwo.go#L10): IsPowOfTwoUseLog This function checks if a number is a power of two using the logarithm. The limiting degree can be from 0 to 63. See alternatives in the binary package.
8. [`LiouvilleLambda`](./math/liouville.go#L24): Lambda is the liouville function This function returns λ(n) for given number
9. [`Mean`](./math/mean.go#L7): No description provided.
10. [`Median`](./math/median.go#L12): No description provided.
11. [`Mode`](./math/mode.go#L19): No description provided.
12. [`Mu`](./math/mobius.go#L21): Mu is the Mobius function This function returns μ(n) for given number
13. [`Phi`](./math/eulertotient.go#L5): Phi is the Euler totient function. This function computes the number of numbers less then n that are coprime with n.
14. [`PollardsRhoFactorization`](./math/pollard.go#L29): PollardsRhoFactorization is an implementation of Pollard's rho factorization algorithm using the default parameters x = y = 2
15. [`Sin`](./math/sin.go#L9): Sin returns the sine of the radian argument x. [See more](https://en.wikipedia.org/wiki/Sine_and_cosine)
7. [`IsPerfectNumber`](./math/perfectnumber.go#L34): Checks if inNumber is a perfect number
8. [`IsPowOfTwoUseLog`](./math/checkisnumberpoweroftwo.go#L10): IsPowOfTwoUseLog This function checks if a number is a power of two using the logarithm. The limiting degree can be from 0 to 63. See alternatives in the binary package.
9. [`Lerp`](./math/lerp.go#L5): Lerp or Linear interpolation This function will return new value in 't' percentage between 'v0' and 'v1'
10. [`LiouvilleLambda`](./math/liouville.go#L24): Lambda is the liouville function This function returns λ(n) for given number
11. [`Mean`](./math/mean.go#L7): No description provided.
12. [`Median`](./math/median.go#L12): No description provided.
13. [`Mode`](./math/mode.go#L19): No description provided.
14. [`Mu`](./math/mobius.go#L21): Mu is the Mobius function This function returns μ(n) for given number
15. [`Phi`](./math/eulertotient.go#L5): Phi is the Euler totient function. This function computes the number of numbers less then n that are coprime with n.
16. [`PollardsRhoFactorization`](./math/pollard.go#L29): PollardsRhoFactorization is an implementation of Pollard's rho factorization algorithm using the default parameters x = y = 2
17. [`Sin`](./math/sin.go#L9): Sin returns the sine of the radian argument x. [See more](https://en.wikipedia.org/wiki/Sine_and_cosine)
18. [`SumOfProperDivisors`](./math/perfectnumber.go#L17): Returns the sum of proper divisors of inNumber.

---
</details><details>
Expand All @@ -523,7 +543,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:

1. [`Bitwise`](./math/max/bitwisemax.go#L11): Bitwise computes using bitwise operator the maximum of all the integer input and returns it
2. [`Int`](./math/max/max.go#L4): Int is a function which returns the maximum of all the integers provided as arguments.
2. [`Int`](./math/max/max.go#L6): Int is a function which returns the maximum of all the integers provided as arguments.

---
</details><details>
Expand All @@ -547,7 +567,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:

1. [`Bitwise`](./math/min/bitwisemin.go#L11): Bitwise This function returns the minimum integer using bit operations
2. [`Int`](./math/min/min.go#L4): Int is a function which returns the minimum of all the integers provided as arguments.
2. [`Int`](./math/min/min.go#L6): Int is a function which returns the minimum of all the integers provided as arguments.

---
</details><details>
Expand All @@ -558,7 +578,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
##### Functions:

1. [`Exponentiation`](./math/modular/exponentiation.go#L22): Exponentiation returns base^exponent % mod
2. [`Inverse`](./math/modular/inverse.go#L20): Inverse Modular function
2. [`Inverse`](./math/modular/inverse.go#L19): Inverse Modular function
3. [`Multiply64BitInt`](./math/modular/exponentiation.go#L51): Multiply64BitInt Checking if the integer multiplication overflows

---
Expand Down Expand Up @@ -715,6 +735,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
9. [`OptimizedTrialDivision`](./math/prime/primecheck.go#L26): OptimizedTrialDivision checks primality of an integer using an optimized trial division method. The optimizations include not checking divisibility by the even numbers and only checking up to the square root of the given number.
10. [`Sieve`](./math/prime/sieve.go#L16): Sieve Sieving the numbers that are not prime from the channel - basically removing them from the channels
11. [`TrialDivision`](./math/prime/primecheck.go#L9): TrialDivision tests whether a number is prime by trying to divide it by the numbers less than it.
12. [`Twin`](./math/prime/twin.go#L15): This function returns twin prime for given number returns (n + 2) if both n and (n + 2) are prime -1 otherwise

---
</details><details>
Expand Down Expand Up @@ -836,29 +857,26 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
2. [`Comb`](./sort/combSort.go#L17): Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm.
3. [`Count`](./sort/countingsort.go#L11): No description provided.
4. [`Exchange`](./sort/exchangesort.go#L8): No description provided.
5. [`HeapSort`](./sort/heapsort.go#L121): No description provided.
5. [`HeapSort`](./sort/heapsort.go#L116): No description provided.
6. [`ImprovedSimple`](./sort/simplesort.go#L27): ImprovedSimple is a improve SimpleSort by skipping an unnecessary comparison of the first and last. This improved version is more similar to implementation of insertion sort
7. [`Insertion`](./sort/insertionsort.go#L5): No description provided.
8. [`Merge`](./sort/mergesort.go#L40): Merge Perform merge sort on a slice
9. [`MergeIter`](./sort/mergesort.go#L54): No description provided.
10. [`Partition`](./sort/quicksort.go#L12): No description provided.
11. [`Patience`](./sort/patiencesort.go#L13): No description provided.
12. [`Pigeonhole`](./sort/pigeonholesort.go#L12): Pigeonhole sorts a slice using pigeonhole sorting algorithm.
13. [`Quicksort`](./sort/quicksort.go#L39): Quicksort Sorts the entire array
14. [`QuicksortRange`](./sort/quicksort.go#L26): QuicksortRange Sorts the specified range within the array
15. [`RadixSort`](./sort/radixsort.go#L35): No description provided.
16. [`Selection`](./sort/selectionsort.go#L5): No description provided.
17. [`Shell`](./sort/shellsort.go#L5): No description provided.
18. [`Simple`](./sort/simplesort.go#L13): No description provided.
8. [`Merge`](./sort/mergesort.go#L41): Merge Perform merge sort on a slice
9. [`MergeIter`](./sort/mergesort.go#L55): No description provided.
10. [`ParallelMerge`](./sort/mergesort.go#L66): ParallelMerge Perform merge sort on a slice using goroutines
11. [`Partition`](./sort/quicksort.go#L12): No description provided.
12. [`Patience`](./sort/patiencesort.go#L13): No description provided.
13. [`Pigeonhole`](./sort/pigeonholesort.go#L15): Pigeonhole sorts a slice using pigeonhole sorting algorithm. NOTE: To maintain time complexity O(n + N), this is the reason for having only Integer constraint instead of Ordered.
14. [`Quicksort`](./sort/quicksort.go#L39): Quicksort Sorts the entire array
15. [`QuicksortRange`](./sort/quicksort.go#L26): QuicksortRange Sorts the specified range within the array
16. [`RadixSort`](./sort/radixsort.go#L43): No description provided.
17. [`Selection`](./sort/selectionsort.go#L5): No description provided.
18. [`Shell`](./sort/shellsort.go#L5): No description provided.
19. [`Simple`](./sort/simplesort.go#L13): No description provided.

---
##### Types

1. [`Int`](#L0):

Methods:
1. [`More`](./sort/heapsort.go#L114): No description provided.
2. [`MaxHeap`](./sort/heapsort.go#L3): No description provided.
1. [`MaxHeap`](./sort/heapsort.go#L5): No description provided.


---
Expand Down
14 changes: 13 additions & 1 deletion cipher/rot13/rot13_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ func TestRot13Decrypt(t *testing.T) {
func assertRot13Output(t *testing.T, input, expected string) {
actual := rot13(input)
if actual != expected {
t.Fatalf("With input string '%s' was expecting '%s' but actual was '%s'",
t.Fatalf("With input string %q was expecting %q but actual was %q",
input, expected, actual)
}
}

func FuzzRot13(f *testing.F) {
for _, rot13TestInput := range rot13TestData {
f.Add(rot13TestInput.input)
}
f.Fuzz(func(t *testing.T, input string) {
if result := rot13(rot13(input)); result != input {
t.Fatalf("With input string %q was expecting %q but actual was %q",
input, input, result)
}
})
}

0 comments on commit 213cfa6

Please sign in to comment.