From 6aefc11a51da808b5039703abd8dff4cd969dbe4 Mon Sep 17 00:00:00 2001 From: Princejeet Singh Sandhu Date: Sat, 18 Nov 2017 20:54:40 -0500 Subject: [PATCH 1/3] Added gitIgnoreFile --- java/.gitignore | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 java/.gitignore diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000..6a8667c --- /dev/null +++ b/java/.gitignore @@ -0,0 +1,64 @@ + +# Created by https://www.gitignore.io/api/intellij+all + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Ruby plugin and RubyMine +/.rakeTasks + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Intellij+all Patch ### +# Ignores the whole idea folder +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# End of https://www.gitignore.io/api/intellij+all From ca4fca03fb4c850bf15ae13eca0625361a9ab8fe Mon Sep 17 00:00:00 2001 From: Princejeet Singh Sandhu Date: Sat, 18 Nov 2017 20:57:21 -0500 Subject: [PATCH 2/3] Added the structure of code files --- java/.gitignore | 2 ++ java/Test/TestFibonacci.java | 7 +++++++ java/Test/TestLargestDifference.java | 7 +++++++ java/Test/TestNumberOfRepeats.java | 7 +++++++ java/src/Fibonacci.java | 5 +++++ java/src/LargestDifference.java | 5 +++++ java/src/NumberOfRepeats.java | 5 +++++ 7 files changed, 38 insertions(+) create mode 100644 java/Test/TestFibonacci.java create mode 100644 java/Test/TestLargestDifference.java create mode 100644 java/Test/TestNumberOfRepeats.java create mode 100644 java/src/Fibonacci.java create mode 100644 java/src/LargestDifference.java create mode 100644 java/src/NumberOfRepeats.java diff --git a/java/.gitignore b/java/.gitignore index 6a8667c..0ef0cca 100644 --- a/java/.gitignore +++ b/java/.gitignore @@ -5,6 +5,8 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +*.iml + # User-specific stuff: .idea/**/workspace.xml .idea/**/tasks.xml diff --git a/java/Test/TestFibonacci.java b/java/Test/TestFibonacci.java new file mode 100644 index 0000000..b898de8 --- /dev/null +++ b/java/Test/TestFibonacci.java @@ -0,0 +1,7 @@ +public class TestFibonacci extends TestCase{ + + private void testCase1(){ + + } + +} \ No newline at end of file diff --git a/java/Test/TestLargestDifference.java b/java/Test/TestLargestDifference.java new file mode 100644 index 0000000..cb4a555 --- /dev/null +++ b/java/Test/TestLargestDifference.java @@ -0,0 +1,7 @@ +public class TestLargestDifference extends TestCase{ + + private void testCase1(){ + + } + +} \ No newline at end of file diff --git a/java/Test/TestNumberOfRepeats.java b/java/Test/TestNumberOfRepeats.java new file mode 100644 index 0000000..b516eb3 --- /dev/null +++ b/java/Test/TestNumberOfRepeats.java @@ -0,0 +1,7 @@ +public class TestNumberOfRepeats extends TestCase{ + + private void testCase1(){ + + } + +} \ No newline at end of file diff --git a/java/src/Fibonacci.java b/java/src/Fibonacci.java new file mode 100644 index 0000000..741249a --- /dev/null +++ b/java/src/Fibonacci.java @@ -0,0 +1,5 @@ +public class Fibonacci{ + public int findNthFibonacci(int n){ + /* TODO: write your code here */ + } +} \ No newline at end of file diff --git a/java/src/LargestDifference.java b/java/src/LargestDifference.java new file mode 100644 index 0000000..5599a49 --- /dev/null +++ b/java/src/LargestDifference.java @@ -0,0 +1,5 @@ +public class LargestDifference{ + public int findLargestDifference(int[] inputArray){ + /* TODO: write your code here */ + } +} \ No newline at end of file diff --git a/java/src/NumberOfRepeats.java b/java/src/NumberOfRepeats.java new file mode 100644 index 0000000..7b85e44 --- /dev/null +++ b/java/src/NumberOfRepeats.java @@ -0,0 +1,5 @@ +public class NumberOfRepeats{ + public int findNumberOfRepeats(String a, String b){ + /* TODO: write your code here */ + } +} \ No newline at end of file From 6f97d65606253f2d9ddb75acad388877a766168e Mon Sep 17 00:00:00 2001 From: Princejeet Singh Sandhu Date: Sat, 18 Nov 2017 21:32:48 -0500 Subject: [PATCH 3/3] Added testcases and made functions static --- java/Test/TestFibonacci.java | 35 ++++++++++++++++++++++++-- java/Test/TestLargestDifference.java | 36 ++++++++++++++++++++++++--- java/Test/TestNumberOfRepeats.java | 37 +++++++++++++++++++++++++++- java/src/Fibonacci.java | 3 ++- java/src/LargestDifference.java | 3 ++- java/src/NumberOfRepeats.java | 3 ++- 6 files changed, 108 insertions(+), 9 deletions(-) diff --git a/java/Test/TestFibonacci.java b/java/Test/TestFibonacci.java index b898de8..98fcc60 100644 --- a/java/Test/TestFibonacci.java +++ b/java/Test/TestFibonacci.java @@ -1,7 +1,38 @@ -public class TestFibonacci extends TestCase{ +import junit.framework.Assert; +import org.junit.jupiter.api.Test; - private void testCase1(){ +public class TestFibonacci{ + @Test + public void testCase1(){ + int input = 0; + int expectedOutput = 0; + int actualOutput = Fibonacci.findNthFibonacci(input); + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void testCase2(){ + int input = 1; + int expectedOutput = 1; + int actualOutput = Fibonacci.findNthFibonacci(input); + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void testCase3(){ + int input = 2; + int expectedOutput = 1; + int actualOutput = Fibonacci.findNthFibonacci(input); + Assert.assertEquals(expectedOutput, actualOutput); + } + + @Test + public void testCase4(){ + int input = 4; + int expectedOutput = 2; + int actualOutput = Fibonacci.findNthFibonacci(input); + Assert.assertEquals(expectedOutput, actualOutput); } } \ No newline at end of file diff --git a/java/Test/TestLargestDifference.java b/java/Test/TestLargestDifference.java index cb4a555..ae14ef6 100644 --- a/java/Test/TestLargestDifference.java +++ b/java/Test/TestLargestDifference.java @@ -1,7 +1,37 @@ -public class TestLargestDifference extends TestCase{ +import junit.framework.Assert; +import org.junit.jupiter.api.Test; - private void testCase1(){ +public class TestLargestDifference{ + @Test + public void testCase1(){ + int[] inputArray = {1,5,9,16,28,35}; + int expectedAnswer = 34; + int actualAnswer = LargestDifference.findLargestDifference(inputArray); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + + @Test + public void testCase2(){ + int[] inputArray = {7,19,15,13,3}; + int expectedAnswer = 12; + int actualAnswer = LargestDifference.findLargestDifference(inputArray); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + + @Test + public void testCase3(){ + int[] inputArray = {1,1,1,1,1,1,1}; + int expectedAnswer = 0; + int actualAnswer = LargestDifference.findLargestDifference(inputArray); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + + @Test + public void testCase4(){ + int[] inputArray = {5,4,3,2,1}; + int expectedAnswer = -1; + int actualAnswer = LargestDifference.findLargestDifference(inputArray); + Assert.assertEquals(expectedAnswer, actualAnswer); } - } \ No newline at end of file diff --git a/java/Test/TestNumberOfRepeats.java b/java/Test/TestNumberOfRepeats.java index b516eb3..f1ad739 100644 --- a/java/Test/TestNumberOfRepeats.java +++ b/java/Test/TestNumberOfRepeats.java @@ -1,7 +1,42 @@ -public class TestNumberOfRepeats extends TestCase{ +import junit.framework.Assert; +import org.junit.jupiter.api.Test; +public class TestNumberOfRepeats { + + @Test private void testCase1(){ + String a = "abcde"; + String b = "abcdabcdabcd"; + int expectedAnswer = -1; + int actualAnswer = NumberOfRepeats.findNumberOfRepeats(a,b); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + + @Test + private void testCase2(){ + String a = "abcd"; + String b = "abcdabdcabcd"; + int expectedAnswer = -1; + int actualAnswer = NumberOfRepeats.findNumberOfRepeats(a,b); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + + @Test + private void testCase3(){ + String a = "aaab"; + String b = "baaabaa"; + int expectedAnswer = 3; + int actualAnswer = NumberOfRepeats.findNumberOfRepeats(a,b); + Assert.assertEquals(expectedAnswer, actualAnswer); + } + @Test + private void testCase4(){ + String a = "abcde"; + String b = "abcdabcdabcd"; + int expectedAnswer = -1; + int actualAnswer = NumberOfRepeats.findNumberOfRepeats(a,b); + Assert.assertEquals(expectedAnswer, actualAnswer); } } \ No newline at end of file diff --git a/java/src/Fibonacci.java b/java/src/Fibonacci.java index 741249a..e7cb16f 100644 --- a/java/src/Fibonacci.java +++ b/java/src/Fibonacci.java @@ -1,5 +1,6 @@ public class Fibonacci{ - public int findNthFibonacci(int n){ + public static int findNthFibonacci(int n){ /* TODO: write your code here */ + throw new UnsupportedOperationException(); } } \ No newline at end of file diff --git a/java/src/LargestDifference.java b/java/src/LargestDifference.java index 5599a49..764be02 100644 --- a/java/src/LargestDifference.java +++ b/java/src/LargestDifference.java @@ -1,5 +1,6 @@ public class LargestDifference{ - public int findLargestDifference(int[] inputArray){ + public static int findLargestDifference(int[] inputArray){ /* TODO: write your code here */ + throw new UnsupportedOperationException(); } } \ No newline at end of file diff --git a/java/src/NumberOfRepeats.java b/java/src/NumberOfRepeats.java index 7b85e44..8061e6e 100644 --- a/java/src/NumberOfRepeats.java +++ b/java/src/NumberOfRepeats.java @@ -1,5 +1,6 @@ public class NumberOfRepeats{ - public int findNumberOfRepeats(String a, String b){ + public static int findNumberOfRepeats(String a, String b){ /* TODO: write your code here */ + throw new UnsupportedOperationException(); } } \ No newline at end of file