diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b49563..1600b7e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index b0ceb78..ce708e6 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ - Please do not add a signature inside the code. The commit history is sufficient to determine who has added the code to the repo. - Make sure the algorithm which is getting added comes under a certain domain of Algorithms. Please don't create a package with a name such as Misc, Others, etc. - While making a PR, make sure you are committing the Kotlin files only and not any project specific files. If you feel that your IDE is generating some extra files, then either don't add them to git, or add the extensions to ```.gitignore```. - - Please don't raise a PR for solutions to problems from online judges such as Hackerrank, Leetcode, etc. + - Please don't raise a PR for solutions to problems from online judges such as HackerRank, LeetCode, etc. ## Steps to raise a PR - Fork the [Kotlin Repo](https://github.com/TheAlgorithms/Kotlin) - Open the forked repo on your local machine through IntelliJ by importing the project as a Gradle project - Make the changes on your local machine - Push the changes to the forked repository -- Raise a PR against the master branch +- Raise a PR against the master branch \ No newline at end of file diff --git a/build.gradle b/build.gradle index a301a3b..1051c0c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.3.21' + id 'org.jetbrains.kotlin.jvm' version '1.6.10' } group 'main.kotlin.com' @@ -14,7 +14,7 @@ repositories { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testCompile group: 'junit', name: 'junit', version: '4.12' + testImplementation group: 'junit', name: 'junit', version: '4.12' } compileKotlin { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 115e6ac..fe753c9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/src/main/kotlin/dynamicProgramming/AssemblyLineScheduling.kt b/src/main/kotlin/dynamicProgramming/AssemblyLineScheduling.kt index e292317..1577ae1 100644 --- a/src/main/kotlin/dynamicProgramming/AssemblyLineScheduling.kt +++ b/src/main/kotlin/dynamicProgramming/AssemblyLineScheduling.kt @@ -8,26 +8,25 @@ import kotlin.math.min * @Params n- number of stations, a- service time at each station, t- line switch time from each station, e- entry time, x- exit time * @Return minimum time to cross n stations * */ -fun AssemblyLineScheduling(n:Int,a:Array,t:Array,e:IntArray,x:IntArray):Int { +fun assemblyLineScheduling(n:Int, a:Array, t:Array, e:IntArray, x:IntArray):Int { - var L1:IntArray = IntArray(n); - var L2:IntArray = IntArray(n) ; - var i=0; + val line1 = IntArray(n) + val line2 = IntArray(n) - L1[0] = e[0] + a[0][0]; + line1[0] = e[0] + a[0][0] - L2[0] = e[1] + a[1][0]; + line2[0] = e[1] + a[1][0] - for(i in 1..n-1) + for(i in 1 until n) { - L1[i] = min(L1[i - 1] + a[0][i], - L2[i - 1] + t[1][i] + a[0][i]); - L2[i] = min(L2[i - 1] + a[1][i], - L1[i - 1] + t[0][i] + a[1][i]); + line1[i] = min(line1[i - 1] + a[0][i], + line2[i - 1] + t[1][i] + a[0][i]) + line2[i] = min(line2[i - 1] + a[1][i], + line1[i - 1] + t[0][i] + a[1][i]) } - return min(L1[n-1] + x[0], - L2[n-1] + x[1]); + return min(line1[n-1] + x[0], + line2[n-1] + x[1]) -} +} \ No newline at end of file diff --git a/src/main/kotlin/dynamicProgramming/LCS.kt b/src/main/kotlin/dynamicProgramming/LCS.kt index 7db3edd..ea8a4db 100644 --- a/src/main/kotlin/dynamicProgramming/LCS.kt +++ b/src/main/kotlin/dynamicProgramming/LCS.kt @@ -10,14 +10,14 @@ import kotlin.math.max */ fun lcs(s1: String, s2: String): Int { - val L = Array(s1.length + 1) { IntArray(s2.length + 1) } + val l = Array(s1.length + 1) { IntArray(s2.length + 1) } for (i in 0..s1.length) { for (j in 0..s2.length) { - if (i == 0 || j == 0) L[i][j] = 0 - else if (s1[i - 1] == s2[j - 1]) L[i][j] = L[i - 1][j - 1] + 1 - else L[i][j] = max(L[i - 1][j], L[i][j - 1]) + if (i == 0 || j == 0) l[i][j] = 0 + else if (s1[i - 1] == s2[j - 1]) l[i][j] = l[i - 1][j - 1] + 1 + else l[i][j] = max(l[i - 1][j], l[i][j - 1]) } } - return L[s1.length][s2.length] + return l[s1.length][s2.length] } \ No newline at end of file diff --git a/src/main/kotlin/dynamicProgramming/MatrixChainMultiplication.kt b/src/main/kotlin/dynamicProgramming/MatrixChainMultiplication.kt index aa47061..1a81871 100644 --- a/src/main/kotlin/dynamicProgramming/MatrixChainMultiplication.kt +++ b/src/main/kotlin/dynamicProgramming/MatrixChainMultiplication.kt @@ -5,13 +5,13 @@ package dynamicProgramming * @Params p- array which represents the chain of matrices such that the ith matrix Ai is of dimension p[i-1] x p[i] * @Return minimum number of multiplications needed to multiply the chain * */ -fun MatrixChainOrder(p: IntArray): Int { +fun matrixChainOrder(p: IntArray): Int { val m = Array(p.size) { IntArray(p.size) } var i: Int var j: Int var k: Int - var L: Int + var l: Int var q: Int i = 1 @@ -20,11 +20,11 @@ fun MatrixChainOrder(p: IntArray): Int { i++ } - L = 2 - while (L < p.size) { + l = 2 + while (l < p.size) { i = 1 - while (i < p.size - L + 1) { - j = i + L - 1 + while (i < p.size - l + 1) { + j = i + l - 1 if (j == p.size) { i++ continue @@ -40,7 +40,7 @@ fun MatrixChainOrder(p: IntArray): Int { } i++ } - L++ + l++ } return m[1][p.size - 1] } \ No newline at end of file diff --git a/src/main/kotlin/dynamicProgramming/ZeroOneKnapsackProblem.kt b/src/main/kotlin/dynamicProgramming/ZeroOneKnapsackProblem.kt index 5460183..d1bf3be 100644 --- a/src/main/kotlin/dynamicProgramming/ZeroOneKnapsackProblem.kt +++ b/src/main/kotlin/dynamicProgramming/ZeroOneKnapsackProblem.kt @@ -8,7 +8,7 @@ import kotlin.math.max * @return Maximum value that can be obtained */ -fun zerooneknapsack(W:Int, weight: IntArray, values:IntArray, n:Int):Int{ +fun zeroOneKnapsack(W:Int, weight: IntArray, values:IntArray, n:Int):Int{ if (W<0) return 0 val k = Array(n+1) {IntArray(W+1) {0} } for (i in 0..n) diff --git a/src/main/kotlin/dynamic_programming/PalindromePartitioning.kt b/src/main/kotlin/dynamic_programming/PalindromePartitioning.kt index b4dd1f1..251bb1e 100644 --- a/src/main/kotlin/dynamic_programming/PalindromePartitioning.kt +++ b/src/main/kotlin/dynamic_programming/PalindromePartitioning.kt @@ -13,9 +13,9 @@ package dynamic_programming /** - * @param String is the string to be checked - * @param Int is the starting index of the string in consideration - * @param Int is the ending index of the string in consideration + * @param string is the string to be checked + * @param i is the starting index of the string in consideration + * @param j is the ending index of the string in consideration * @return whether string is a palindrome or not **/ fun isPalindrome(string: String, i: Int, j: Int): Boolean { @@ -29,9 +29,9 @@ fun isPalindrome(string: String, i: Int, j: Int): Boolean { /** - * @param String is the string to be checked - * @param Int is the starting index of the string in consideration - * @param Int is the ending index of the string in consideration + * @param string is the string to be checked + * @param i is the starting index of the string in consideration + * @param j is the ending index of the string in consideration * @return minimum number of partitions required **/ fun palindromePartition(string: String, i: Int, j: Int): Int { @@ -63,9 +63,9 @@ lateinit var dp: Array> /** - * @param String the string on which algorithm is to be operated + * @param string the string on which algorithm is to be operated */ fun initialize(string: String): Int { dp = Array(string.length) { Array(string.length) { -1 } } return palindromePartition(string, 0, string.length - 1) -} +} \ No newline at end of file diff --git a/src/main/kotlin/math/Area.kt b/src/main/kotlin/math/Area.kt index a318708..64f27ae 100644 --- a/src/main/kotlin/math/Area.kt +++ b/src/main/kotlin/math/Area.kt @@ -1,6 +1,5 @@ package math -import java.lang.IllegalArgumentException import kotlin.math.pow /** diff --git a/src/main/kotlin/math/Factorial.kt b/src/main/kotlin/math/Factorial.kt index e33be00..1e64d74 100644 --- a/src/main/kotlin/math/Factorial.kt +++ b/src/main/kotlin/math/Factorial.kt @@ -1,4 +1,4 @@ -package mathematics +package math import java.security.InvalidParameterException diff --git a/src/main/kotlin/other/Palindrome.kt b/src/main/kotlin/other/Palindrome.kt index 4a2dc13..902c96d 100644 --- a/src/main/kotlin/other/Palindrome.kt +++ b/src/main/kotlin/other/Palindrome.kt @@ -1,6 +1,7 @@ package other import java.text.Normalizer +import java.util.Locale import java.util.regex.Pattern /** @@ -20,7 +21,7 @@ fun isPalindrome(text: String): Boolean { for(i in normalizedText.indices) if(normalizedText[i] != normalizedText[normalizedText.length - (i + 1)]) return false - return true; + return true } @@ -30,7 +31,7 @@ fun String.normalize(): String { .compile("\\p{InCombiningDiacriticalMarks}+") .matcher(nfdNormalizedString) .replaceAll("") - .toLowerCase() + .lowercase(Locale.getDefault()) .replace(" ", "") } \ No newline at end of file diff --git a/src/main/kotlin/search/BinarySearch.kt b/src/main/kotlin/search/BinarySearch.kt index d3d5c5d..7c97a03 100644 --- a/src/main/kotlin/search/BinarySearch.kt +++ b/src/main/kotlin/search/BinarySearch.kt @@ -3,9 +3,9 @@ package search /** * Binary search is an algorithm which finds the position of a target value within an array (Sorted) * - * Worst-case performance O(log(n)) - * Best-case performance O(1) - * Average performance O(log(n)) + * Worst-case performance O(log(n)) + * Best-case performance O(1) + * Average performance O(log(n)) * Worst-case space complexity O(1) */ @@ -32,7 +32,7 @@ fun > binarySearchHelper(array: Array, key: T, start: Int, return when { array[mid].compareTo(key) == 0 -> mid - array[mid].compareTo(key) > 0 -> binarySearchHelper(array, key, start, mid - 1) + array[mid] > key -> binarySearchHelper(array, key, start, mid - 1) else -> binarySearchHelper(array, key, mid + 1, end) } -} +} \ No newline at end of file diff --git a/src/main/kotlin/search/InterpolationSearch.kt b/src/main/kotlin/search/InterpolationSearch.kt index e309334..9174b4a 100644 --- a/src/main/kotlin/search/InterpolationSearch.kt +++ b/src/main/kotlin/search/InterpolationSearch.kt @@ -3,9 +3,9 @@ package search /** * Interpolation search is an algorithm which finds the position of a target value within an array (Sorted) * - * Worst-case performance O(n) - * Best-case performance O(1) - * Average performance O(log log n) + * Worst-case performance O(n) + * Best-case performance O(1) + * Average performance O(log(log(n))) * Worst-case space complexity O(1) */ diff --git a/src/main/kotlin/search/LinearSearch.kt b/src/main/kotlin/search/LinearSearch.kt index b82837d..b284e16 100644 --- a/src/main/kotlin/search/LinearSearch.kt +++ b/src/main/kotlin/search/LinearSearch.kt @@ -3,11 +3,11 @@ package search /** * Linear search is an algorithm which finds the position of a target value within an array (Usually unsorted) * - * Worst-case performance O(n) - * Best-case performance O(1) - * Average performance O(n) + * Worst-case performance O(n) + * Best-case performance O(1) + * Average performance O(n) * Worst-case space complexity O(1) - */ + **/ /** * @param array is an array where the element should be found @@ -31,4 +31,4 @@ fun > linearSearchImpl(array: Array, key: T): Int { } return -1 -} +} \ No newline at end of file diff --git a/src/main/kotlin/search/TernarySearch.kt b/src/main/kotlin/search/TernarySearch.kt index 2d26e6a..7ba1789 100644 --- a/src/main/kotlin/search/TernarySearch.kt +++ b/src/main/kotlin/search/TernarySearch.kt @@ -3,11 +3,9 @@ package search /** * Complexity Analysis: * - * Time Complexity: O(log3 n) - * Space Complexity: O(1) - * - */ - + * Time Complexity: O(log3 n) + * Space Complexity: O(1) + **/ fun ternarySearch(l: Double, r: Double, func: (Double) -> Double, eps: Double = 1e-3): Double { var left = l var right = r @@ -21,4 +19,4 @@ fun ternarySearch(l: Double, r: Double, func: (Double) -> Double, eps: Double = } } return left -} +} \ No newline at end of file diff --git a/src/main/kotlin/sort/BrickSort.kt b/src/main/kotlin/sort/BrickSort.kt index 47c222e..9550dda 100644 --- a/src/main/kotlin/sort/BrickSort.kt +++ b/src/main/kotlin/sort/BrickSort.kt @@ -6,12 +6,11 @@ package sort * @param array The array to be sorted * Sorts the array in increasing order * - * Worst-case performance O(n^2) - * Best-case performance O(n) - * Average performance O(n^2) + * Worst-case performance O(n^2) + * Best-case performance O(n) + * Average performance O(n^2) * Worst-case space complexity O(1) **/ - fun > oddEvenSort(array: Array) { var isSorted = false while (!isSorted) { diff --git a/src/main/kotlin/sort/BubbleSort.kt b/src/main/kotlin/sort/BubbleSort.kt index c9bc384..344b6f1 100644 --- a/src/main/kotlin/sort/BubbleSort.kt +++ b/src/main/kotlin/sort/BubbleSort.kt @@ -6,9 +6,9 @@ package sort * @param array The array to be sorted * Sorts the array in increasing order * - * Worst-case performance O(n^2) - * Best-case performance O(n) - * Average performance O(n^2) + * Worst-case performance O(n^2) + * Best-case performance O(n) + * Average performance O(n^2) * Worst-case space complexity O(1) **/ fun > bubbleSort(array: Array) { @@ -39,4 +39,4 @@ fun > swapElements(array: Array, idx1: Int, idx2: Int) { array[idx1] = array[idx2].also { array[idx2] = array[idx1] } -} +} \ No newline at end of file diff --git a/src/main/kotlin/sort/HeapSort.kt b/src/main/kotlin/sort/HeapSort.kt index 7f70e65..f1aae09 100644 --- a/src/main/kotlin/sort/HeapSort.kt +++ b/src/main/kotlin/sort/HeapSort.kt @@ -8,9 +8,9 @@ package sort * * Worst-case performance O(n*log(n)) * Best-case performance O(n*log(n)) - * Average-case performance O(n*log(n)) + * Average performance O(n*log(n)) * Worst-case space complexity O(1) (auxiliary) - */ + **/ fun > heapSort(array: Array) { buildMaxHeap(array) transformMaxHeapToSortedArray(array) @@ -23,7 +23,7 @@ fun > heapSort(array: Array) { * @param array The array containing the elements * @param index Index of the currently largest element */ -fun > maxheapify(array: Array, heapSize: Int, index: Int) { +fun > maxHeapify(array: Array, heapSize: Int, index: Int) { val left = 2 * index + 1 val right = 2 * index + 2 var largest = index @@ -34,7 +34,7 @@ fun > maxheapify(array: Array, heapSize: Int, index: Int) { largest = right if (largest != index) { swapElements(array, index, largest) - maxheapify(array, heapSize, largest) + maxHeapify(array, heapSize, largest) } } @@ -46,7 +46,7 @@ fun > maxheapify(array: Array, heapSize: Int, index: Int) { private fun > buildMaxHeap(array: Array) { val n = array.size for (i in (n / 2 - 1) downTo 0) - maxheapify(array, n, i) + maxHeapify(array, n, i) } /** @@ -58,7 +58,6 @@ private fun > buildMaxHeap(array: Array) { private fun > transformMaxHeapToSortedArray(array: Array) { for (i in (array.size - 1) downTo 0) { swapElements(array, i, 0) - maxheapify(array, i, 0) + maxHeapify(array, i, 0) } -} - +} \ No newline at end of file diff --git a/src/main/kotlin/sort/InsertionSort.kt b/src/main/kotlin/sort/InsertionSort.kt index c3d4f04..a2bc0fd 100644 --- a/src/main/kotlin/sort/InsertionSort.kt +++ b/src/main/kotlin/sort/InsertionSort.kt @@ -6,9 +6,9 @@ package sort * @param array The array to be sorted * Sorts the array in increasing order * - * Worst-case performance O(n^2) - * Best-case performance O(n) - * Average performance O(n^2) + * Worst-case performance O(n^2) + * Best-case performance O(n) + * Average performance O(n^2) * Worst-case space complexity O(1) **/ fun > insertionSort(array: Array) { @@ -19,7 +19,7 @@ fun > insertionSort(array: Array) { var idx = i for (j in i - 1 downTo 0) { - if (array[j].compareTo(key) > 0) { + if (array[j] > key) { array[j + 1] = array[j] idx = j } else { diff --git a/src/main/kotlin/sort/MergeSort.kt b/src/main/kotlin/sort/MergeSort.kt index c99bcf9..8cbca40 100644 --- a/src/main/kotlin/sort/MergeSort.kt +++ b/src/main/kotlin/sort/MergeSort.kt @@ -6,11 +6,11 @@ package sort * @param array The array to be sorted * It is a Divide and Conquer algorithm. It sorts the array by dividing it into two halves and comparing the elements. * - * Worst-case performance O(n log n) - * Best-case performance O(n log n) - * Average performance O(n log n) + * Worst-case performance O(n*log(n)) + * Best-case performance O(n*log(n)) + * Average performance O(n*log(n)) * Worst-case space complexity O(n) - */ + **/ fun > mergeSort(array: Array, start: Int, end: Int) { val temp = arrayOfNulls>(array.size) as Array diff --git a/src/main/kotlin/sort/QuickSort.kt b/src/main/kotlin/sort/QuickSort.kt index 7cb7fa7..555d98a 100644 --- a/src/main/kotlin/sort/QuickSort.kt +++ b/src/main/kotlin/sort/QuickSort.kt @@ -7,8 +7,8 @@ package sort * It is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. * * Worst-case performance O(n^2) - * Best-case performance O(nLogn) - * Average performance O(nLogn) + * Best-case performance O(n*log(n)) + * Average performance O(n*log(n)) * Worst-case space complexity O(1) **/ fun > quickSort(array: Array, low: Int, high: Int) { diff --git a/src/main/kotlin/sort/SelectionSort.kt b/src/main/kotlin/sort/SelectionSort.kt index ffe0a85..0525546 100644 --- a/src/main/kotlin/sort/SelectionSort.kt +++ b/src/main/kotlin/sort/SelectionSort.kt @@ -6,9 +6,9 @@ package sort * @param array The array to be sorted * Sorts the array by repeatedly finding the minimum element from unsorted part and putting in the beginning * - * Worst-case performance O(n^2) - * Best-case performance O(n^2) - * Average performance O(n^2) + * Worst-case performance O(n^2) + * Best-case performance O(n^2) + * Average performance O(n^2) * Worst-case space complexity O(1) **/ fun > selectionSort(array: Array) { @@ -24,4 +24,4 @@ fun > selectionSort(array: Array) { swapElements(array, i, idx) } -} +} \ No newline at end of file diff --git a/src/test/kotlin/dynamicProgramming/AssemblyLineSchedulingTest.kt b/src/test/kotlin/dynamicProgramming/AssemblyLineSchedulingTest.kt index daaa628..d0880fe 100644 --- a/src/test/kotlin/dynamicProgramming/AssemblyLineSchedulingTest.kt +++ b/src/test/kotlin/dynamicProgramming/AssemblyLineSchedulingTest.kt @@ -6,16 +6,16 @@ class AssemblyLineSchedulingTest{ @Test fun testWith6Stations() { - assert(AssemblyLineScheduling(6,arrayOf(intArrayOf(3, 7, 2, 5,5,3), intArrayOf(4, 1, 6, 7,5,3)),arrayOf(intArrayOf(0,2,3,4,5,6), intArrayOf(0,5,4,3,2,1)), intArrayOf(15,11), intArrayOf(16,5))== 42) + assert(assemblyLineScheduling(6,arrayOf(intArrayOf(3, 7, 2, 5,5,3), intArrayOf(4, 1, 6, 7,5,3)),arrayOf(intArrayOf(0,2,3,4,5,6), intArrayOf(0,5,4,3,2,1)), intArrayOf(15,11), intArrayOf(16,5))== 42) } @Test fun testWith2Stations() { - assert(AssemblyLineScheduling(2,arrayOf(intArrayOf(3, 7), intArrayOf(4, 1)),arrayOf(intArrayOf(0,2), intArrayOf(0,5)), intArrayOf(5,1), intArrayOf(6,5))== 11) + assert(assemblyLineScheduling(2,arrayOf(intArrayOf(3, 7), intArrayOf(4, 1)),arrayOf(intArrayOf(0,2), intArrayOf(0,5)), intArrayOf(5,1), intArrayOf(6,5))== 11) } @Test fun testWith4Stations() { - assert(AssemblyLineScheduling(4,arrayOf(intArrayOf(3, 7,6,2), intArrayOf(4, 1,6,2)),arrayOf(intArrayOf(0,2,6,1), intArrayOf(0,5,3,4)), intArrayOf(7,4), intArrayOf(5,8))== 25) + assert(assemblyLineScheduling(4,arrayOf(intArrayOf(3, 7,6,2), intArrayOf(4, 1,6,2)),arrayOf(intArrayOf(0,2,6,1), intArrayOf(0,5,3,4)), intArrayOf(7,4), intArrayOf(5,8))== 25) } -} +} \ No newline at end of file diff --git a/src/test/kotlin/dynamicProgramming/MatrixChainMultiplicationTest.kt b/src/test/kotlin/dynamicProgramming/MatrixChainMultiplicationTest.kt index a70f81f..ee6bdd4 100644 --- a/src/test/kotlin/dynamicProgramming/MatrixChainMultiplicationTest.kt +++ b/src/test/kotlin/dynamicProgramming/MatrixChainMultiplicationTest.kt @@ -5,11 +5,11 @@ import org.junit.Test class MatrixChainMultiplicationTest { @Test fun testWith5Matrices() { - assert(MatrixChainOrder(intArrayOf(30, 20, 40, 10, 30)) == 23000) + assert(matrixChainOrder(intArrayOf(30, 20, 40, 10, 30)) == 23000) } @Test fun testWith4Matrices() { - assert(MatrixChainOrder(intArrayOf(50, 20, 10, 30)) == 25000) + assert(matrixChainOrder(intArrayOf(50, 20, 10, 30)) == 25000) } } \ No newline at end of file diff --git a/src/test/kotlin/dynamicProgramming/ZeroOneKnapsackProblemTest.kt b/src/test/kotlin/dynamicProgramming/ZeroOneKnapsackProblemTest.kt index 101122f..b327dcc 100644 --- a/src/test/kotlin/dynamicProgramming/ZeroOneKnapsackProblemTest.kt +++ b/src/test/kotlin/dynamicProgramming/ZeroOneKnapsackProblemTest.kt @@ -5,21 +5,21 @@ import org.junit.Test class ZeroOneKnapsackProblemTest { @Test fun testBothWeightAndValueArrayHasDifferentValuesGivesExpectedOutput() { - assert(zerooneknapsack(5, intArrayOf(3,2,1), intArrayOf(20,50,30),3) == 80) + assert(zeroOneKnapsack(5, intArrayOf(3,2,1), intArrayOf(20,50,30),3) == 80) } @Test fun testBothWeightAndValueArrayHasSameValuesGivesExpectedOutput(){ - assert(zerooneknapsack(3, intArrayOf(2,2), intArrayOf(3,3),2)==3) + assert(zeroOneKnapsack(3, intArrayOf(2,2), intArrayOf(3,3),2)==3) } @Test fun testNegativeCapacityGivesZero(){ - assert(zerooneknapsack(-3, intArrayOf(2,2), intArrayOf(3,3),2)==0) + assert(zeroOneKnapsack(-3, intArrayOf(2,2), intArrayOf(3,3),2)==0) } @Test fun testZeroCapacityGivesZero(){ - assert(zerooneknapsack(0, intArrayOf(2,2), intArrayOf(3,3),2)==0) + assert(zeroOneKnapsack(0, intArrayOf(2,2), intArrayOf(3,3),2)==0) } } \ No newline at end of file diff --git a/src/test/kotlin/dynamicProgramming/isPrime.kt b/src/test/kotlin/dynamicProgramming/isPrime.kt index eed411f..b237fba 100644 --- a/src/test/kotlin/dynamicProgramming/isPrime.kt +++ b/src/test/kotlin/dynamicProgramming/isPrime.kt @@ -2,20 +2,20 @@ package dynamicProgramming import org.junit.Test -internal class isPrimeTest { +internal class IsPrimeTest { @Test fun testPrime1(){ - assert(2.isPrime()==true) + assert(2.isPrime()) } @Test fun testPrime2(){ - assert(53.isPrime()==true) + assert(53.isPrime()) } @Test fun testPrime3(){ - assert(4.isPrime()==false) + assert(!4.isPrime()) } } \ No newline at end of file diff --git a/src/test/kotlin/math/AreaTest.kt b/src/test/kotlin/math/AreaTest.kt index 8871c84..d87737a 100644 --- a/src/test/kotlin/math/AreaTest.kt +++ b/src/test/kotlin/math/AreaTest.kt @@ -1,7 +1,6 @@ package math import org.junit.Test -import java.lang.IllegalArgumentException class AreaTest { @Test diff --git a/src/test/kotlin/math/FactorialTest.kt b/src/test/kotlin/math/FactorialTest.kt index 7706828..907b4c3 100644 --- a/src/test/kotlin/math/FactorialTest.kt +++ b/src/test/kotlin/math/FactorialTest.kt @@ -1,4 +1,4 @@ -package mathematics +package math import org.junit.Test import java.security.InvalidParameterException diff --git a/src/test/kotlin/math/Median.kt b/src/test/kotlin/math/Median.kt index dd36b12..3506781 100644 --- a/src/test/kotlin/math/Median.kt +++ b/src/test/kotlin/math/Median.kt @@ -1,6 +1,5 @@ package math -import math.median import org.junit.Test class Median { @@ -21,4 +20,4 @@ class Median { val array = intArrayOf( 2, 3, 4, -2, -8, -3) assert(median(array) == 0.0) } -} +} \ No newline at end of file