Skip to content

Commit a2a0874

Browse files
TejuTeju
Teju
authored and
Teju
committed
'CommitAfterUnitTesting'
1 parent 3df413d commit a2a0874

22 files changed

+1976
-0
lines changed

.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="lib" path="C:/Users/Teju/workspace/Sample/DiamondKinetics/junit-4.10.jar"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>DiamondKinetics</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
11
# DiamondKinetics
22
Solution for the coding challenge round at DiamondKinetics
3+
4+
5+
6+
1. The source file which contains the API is "SensorDataAnalysis.java". "SensorData.java" class holds the sensor data value which are retrieved from the csv file (the csv file is kept
7+
within the src folder for now, you can have many more csv files but kindly specify the path of the csv file as input to the APIs. The data attribute of the API takes in a string value
8+
which would be the path of the csv file on which the criteria has to be checked. This file can be changed at any point in time.
9+
The values from any csv file given are added into an ArrayList<SensorData> which is later retrieved from indexBegin to indexEnd to check for the criteria as per each APIs requirement and
10+
an index value in returned as output.
11+
12+
2. In case of the fourth operation since two index values have to returned I have considered the output to be a string wherein the values are separated by a space.
13+
14+
3. Additionally, I have also written parametrized test cases for each one of the API to test them. You can add many more test data within the parameterized array to check
15+
for the functional correctness of all four operations. Incase I have missed out on something or some of the scenario are incorrect or some edge conditions fail kindly help me with it.
16+
I owuld love to work with you to fix things.
17+
18+
4. In case, the indexEnd - indexBegin < winLength I have returned -1 value, similarly if am not able to find any samples within the winLength window I have returned -1. This is just to handle
19+
the edge conditions.
20+
21+
5. If am totally wrong with my approach, I would like to get some comments/feedback to improvize on the solution that I have obtained.
22+
23+
6. I have not uplaoded the latestSwing.csv file due to confidentiality reasons, kindly place the csv file in the src folder before executing the test cases otherwise it would throw
24+
file not found exception
25+
26+
27+
1.92 KB
Binary file not shown.
1.31 KB
Binary file not shown.
2.29 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2.31 KB
Binary file not shown.

bin/SensorData.class

1.62 KB
Binary file not shown.

bin/SensorDataAnalysis.class

9.72 KB
Binary file not shown.

bin/SensorDataAnalysisAPI.class

7.54 KB
Binary file not shown.

bin/latestSwing.csv

+1,276
Large diffs are not rendered by default.

junit-4.10.jar

247 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import static org.junit.Assert.*;
3+
4+
import java.util.Arrays;
5+
import java.util.Collection;
6+
7+
import org.junit.Assume;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.Parameterized;
11+
import org.junit.runners.Parameterized.Parameters;
12+
13+
@RunWith(Parameterized.class)
14+
public class BackSearchContinuityWithinRangeTest {
15+
16+
@Parameters
17+
public static Collection<Object[]> data() {
18+
return Arrays.asList(new Object[][] {
19+
{ "../DiamondKinetics/src/latestSwing.csv", 90, 0, 0.2, 0.702148, 12, 90},
20+
21+
});
22+
}
23+
24+
private String data;
25+
private int indexBegin,indexEnd,winLength;
26+
private Double thresholdLo,thresholdHi;
27+
private int expected;
28+
29+
public BackSearchContinuityWithinRangeTest(String data, int indexBegin, int indexEnd, Double thresholdLo,
30+
Double thresholdHi, int winLength, int out) {
31+
32+
this.data= data;
33+
this.indexBegin = indexBegin;
34+
this.indexEnd = indexEnd;
35+
this.thresholdLo = thresholdLo;
36+
this.thresholdHi = thresholdHi;
37+
this.winLength = winLength;
38+
this.expected = out;
39+
}
40+
41+
@Test
42+
public void testBackSearchContinuityWithinRange() {
43+
assertEquals(expected, SensorDataAnalysis.backSearchContinuityWithinRange(data,indexBegin,indexEnd,thresholdLo,thresholdHi,winLength));
44+
}
45+
}
46+
47+
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
import static org.junit.Assert.*;
3+
4+
import java.util.Arrays;
5+
import java.util.Collection;
6+
7+
import org.junit.Assume;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.Parameterized;
11+
import org.junit.runners.Parameterized.Parameters;
12+
13+
@RunWith(Parameterized.class)
14+
public class SearchContinuityAboveValueTest {
15+
16+
enum Type {searchContinuityAboveValue,backSearchContinuityWithinRange,searchContinuityAboveValueTwoSignals,searchMultiContinuityWithinRange};
17+
18+
@Parameters
19+
public static Collection<Object[]> data() {
20+
return Arrays.asList(new Object[][] {
21+
{Type.searchContinuityAboveValue,"../DiamondKinetics/src/latestSwing.csv", 139, 145, 0.4564, 3, 139},
22+
{Type.searchContinuityAboveValue,"../DiamondKinetics/src/latestSwing.csv", 0, 10, -17.9999, 12, -1},
23+
{Type.searchContinuityAboveValue,"../DiamondKinetics/src/latestSwing.csv", 0, 25, 4.0, 15, -1},
24+
{Type.searchContinuityAboveValue,"../DiamondKinetics/src/latestSwing.csv", 1200, 1250, 3.0, 40, 1200},
25+
26+
27+
});
28+
}
29+
private Type type;
30+
private String data;
31+
private int indexBegin,indexEnd,winLength;
32+
private Double threshold;
33+
private int expected;
34+
35+
36+
public SearchContinuityAboveValueTest(Type type,String data, int indexBegin, int indexEnd, Double threshold,
37+
int winLength, int out) {
38+
this.type= type;
39+
this.data= data;
40+
this.indexBegin = indexBegin;
41+
this.indexEnd = indexEnd;
42+
this.threshold = threshold;
43+
this.winLength = winLength;
44+
this.expected = out;
45+
}
46+
47+
48+
49+
@Test
50+
public void testSearchContinuityAboveValue() {
51+
Assume.assumeTrue(type == Type.searchContinuityAboveValue);
52+
assertEquals(expected, SensorDataAnalysis.searchContinuityAboveValue(data,indexBegin,indexEnd,threshold,winLength));
53+
}
54+
55+
56+
}
57+
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import static org.junit.Assert.*;
3+
4+
import java.util.Arrays;
5+
import java.util.Collection;
6+
7+
import org.junit.Assume;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.Parameterized;
11+
import org.junit.runners.Parameterized.Parameters;
12+
13+
@RunWith(Parameterized.class)
14+
public class SearchContinuityAboveValueTwoSignalsTest {
15+
16+
enum Type {searchContinuityAboveValueTwoSignals};
17+
18+
@Parameters
19+
public static Collection<Object[]> data() {
20+
return Arrays.asList(new Object[][] {
21+
{Type.searchContinuityAboveValueTwoSignals, "../DiamondKinetics/src/latestSwing.csv", "../DiamondKinetics/src/latestSwing.csv", 2, 90, 0.2, 0.3, 12, 2 },
22+
23+
});
24+
}
25+
private Type type;
26+
private String data1,data2;
27+
private int indexBegin,indexEnd,winLength;
28+
private Double thresholdLo,thresholdHi;
29+
private int expected;
30+
private String expectedOutput;
31+
32+
public SearchContinuityAboveValueTwoSignalsTest(Type type,String data1, String data2, int indexBegin, int indexEnd, Double thresholdLo,
33+
Double thresholdHi, int winLength, int out) {
34+
this.type= type;
35+
this.data1= data1;
36+
this.data2 = data2;
37+
this.indexBegin = indexBegin;
38+
this.indexEnd = indexEnd;
39+
this.thresholdLo = thresholdLo;
40+
this.thresholdHi = thresholdHi;
41+
this.winLength = winLength;
42+
this.expected = out;
43+
}
44+
45+
@Test
46+
public void testSearchContinuityAboveValueTwoSignals() {
47+
Assume.assumeTrue(type == Type.searchContinuityAboveValueTwoSignals);
48+
assertEquals(expected, SensorDataAnalysis.searchContinuityAboveValueTwoSignals(data1,data2,indexBegin,indexEnd,thresholdLo,thresholdHi,winLength));
49+
}
50+
51+
}
52+
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
import static org.junit.Assert.*;
3+
4+
import java.util.Arrays;
5+
import java.util.Collection;
6+
7+
import org.junit.Assume;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.junit.runners.Parameterized;
11+
import org.junit.runners.Parameterized.Parameters;
12+
13+
@RunWith(Parameterized.class)
14+
public class SearchMultiContinuityWithinRangeTest {
15+
16+
enum Type {searchContinuityAboveValue,backSearchContinuityWithinRange,searchContinuityAboveValueTwoSignals,searchMultiContinuityWithinRange};
17+
18+
@Parameters
19+
public static Collection<Object[]> data() {
20+
return Arrays.asList(new Object[][] {
21+
{Type.searchMultiContinuityWithinRange,"../DiamondKinetics/src/latestSwing.csv", 0, 90, 0.2, 0.702148, 12, "0 11" }
22+
});
23+
}
24+
private Type type;
25+
private String data;
26+
private int indexBegin,indexEnd,winLength;
27+
private Double thresholdLo,thresholdHi;
28+
private String expectedOutput;
29+
30+
public SearchMultiContinuityWithinRangeTest(Type type,String data, int indexBegin, int indexEnd, Double thresholdLo, Double thresholdHi, int
31+
winLength, String out) {
32+
this.type= type;
33+
this.data= data;
34+
this.indexBegin = indexBegin;
35+
this.indexEnd = indexEnd;
36+
this.thresholdLo = thresholdLo;
37+
this.thresholdHi = thresholdHi;
38+
this.winLength = winLength;
39+
this.expectedOutput = out;
40+
}
41+
42+
43+
@Test
44+
public void testSearchMultiContinuityWithinRange() {
45+
Assume.assumeTrue(type == Type.searchMultiContinuityWithinRange);
46+
assertEquals(expectedOutput, SensorDataAnalysis.searchMultiContinuityWithinRange(data,indexBegin,indexEnd,thresholdLo,thresholdHi,winLength));
47+
}
48+
49+
}
50+
51+

src/SensorData.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.math.BigInteger;
2+
3+
public class SensorData {
4+
BigInteger timestamp;
5+
public BigInteger getTimestamp() {
6+
return timestamp;
7+
}
8+
public void setTimestamp(BigInteger timestamp) {
9+
this.timestamp = timestamp;
10+
}
11+
public Double getAx() {
12+
return ax;
13+
}
14+
public void setAx(Double ax) {
15+
this.ax = ax;
16+
}
17+
public Double getAy() {
18+
return ay;
19+
}
20+
public void setAy(Double ay) {
21+
this.ay = ay;
22+
}
23+
public Double getAz() {
24+
return az;
25+
}
26+
public void setAz(Double az) {
27+
this.az = az;
28+
}
29+
public Double getBx() {
30+
return bx;
31+
}
32+
public void setBx(Double bx) {
33+
this.bx = bx;
34+
}
35+
public Double getBy() {
36+
return by;
37+
}
38+
public void setBy(Double by) {
39+
this.by = by;
40+
}
41+
public Double getBz() {
42+
return bz;
43+
}
44+
public void setBz(Double bz) {
45+
this.bz = bz;
46+
}
47+
Double ax, ay, az, bx, by, bz;
48+
}

0 commit comments

Comments
 (0)