Tariq Hook hace 6 años
commit
75d7f992a2
Se han modificado 5 ficheros con 330 adiciones y 0 borrados
  1. 49
    0
      .gitignore
  2. 1
    0
      README.md
  3. 19
    0
      pom.xml
  4. 76
    0
      src/main/java/io/zipcoder/ArrayDrills.java
  5. 185
    0
      src/test/java/io/zipcoder/ArrayDrillsTest.java

+ 49
- 0
.gitignore Ver fichero

@@ -0,0 +1,49 @@
1
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
2
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3
+
4
+# User-specific stuff:
5
+.idea/**/workspace.xml
6
+.idea/**/tasks.xml
7
+.idea/dictionaries
8
+
9
+# Sensitive or high-churn files:
10
+.idea/**/dataSources/
11
+.idea/**/dataSources.ids
12
+.idea/**/dataSources.local.xml
13
+.idea/**/sqlDataSources.xml
14
+.idea/**/dynamic.xml
15
+.idea/**/uiDesigner.xml
16
+
17
+# Gradle:
18
+.idea/**/gradle.xml
19
+.idea/**/libraries
20
+
21
+# CMake
22
+cmake-build-debug/
23
+cmake-build-release/
24
+
25
+# Mongo Explorer plugin:
26
+.idea/**/mongoSettings.xml
27
+
28
+## File-based project format:
29
+*.iws
30
+
31
+## Plugin-specific files:
32
+
33
+# IntelliJ
34
+out/
35
+
36
+# mpeltonen/sbt-idea plugin
37
+.idea_modules/
38
+
39
+# JIRA plugin
40
+atlassian-ide-plugin.xml
41
+
42
+# Cursive Clojure plugin
43
+.idea/replstate.xml
44
+
45
+# Crashlytics plugin (for Android Studio and IntelliJ)
46
+com_crashlytics_export_strings.xml
47
+crashlytics.properties
48
+crashlytics-build.properties
49
+fabric.properties

+ 1
- 0
README.md Ver fichero

@@ -0,0 +1 @@
1
+# FundamentalDrills-Part1

+ 19
- 0
pom.xml Ver fichero

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>io.zipcoder</groupId>
8
+    <artifactId>FundamentalDrills-Part1</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
19
+</project>

+ 76
- 0
src/main/java/io/zipcoder/ArrayDrills.java Ver fichero

@@ -0,0 +1,76 @@
1
+package io.zipcoder;
2
+
3
+public class ArrayDrills {
4
+
5
+
6
+    /**
7
+     * Given an array of ints, return true if value appears as either the first or last element in the array.
8
+     * The array will be length 1 or more.
9
+     * example : firstLast(6, [1,2,6); // Should return true
10
+     *           firstLast(6, [1,2,3]); // Should return false
11
+     */
12
+    public Boolean firstLast(Integer value, Integer[] input){
13
+        return null;
14
+    }
15
+
16
+    /**
17
+     * Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are equal.
18
+     * example : sameFirstLast([1,2,3]); // Should return false
19
+     *           sameFirstLast([1,2,1]); // Should return true
20
+     */
21
+    public Boolean sameFirstLast(Integer[] input){
22
+        return null;
23
+    }
24
+
25
+
26
+    /**
27
+     * Given 2 arrays of ints, a and b, return true if they have the same first element or they have the same last element.
28
+     * Both arrays will be length 1 or more.
29
+     * example : commonEnd([1, 2, 3], [7, 3]); // Should return true
30
+     *           commonEnd([1, 2, 3], [7, 3, 2]); // Should return false
31
+     */
32
+    public Boolean commonEnd(Integer[] input1, Integer[] input2){
33
+        return null;
34
+    }
35
+
36
+    /**
37
+     * Given an array of ints, return an array with the elements "rotated left" so {1, 2, 3} yields {2, 3, 1}.
38
+     * example : rotateLeft([1, 2, 3]); // Should return [2,3,1]
39
+     *           rotateLeft([5, 11, 9]); // Should return [11,9,5]
40
+     */
41
+    public Integer[] rotateLeft(Integer[] input){
42
+        return null;
43
+    }
44
+
45
+
46
+    /**
47
+     * Given an array of ints, figure out which is element in the array is largest,
48
+     * and set all the other elements to be that value. Return the changed array.
49
+     * example : maxValue([1, 2, 3]); // Should return [3,3,3]
50
+     *           maxValue([5, 11, 9]); // Should return [11,11,11]
51
+     */
52
+    public Integer[] maxValue(Integer[] input){
53
+        return null;
54
+    }
55
+
56
+
57
+    /**
58
+     * Given 2 int arrays, a and b, return a new array length 2 containing their middle elements, if length is odd.
59
+     * If the array length is even the sum of the middle 2 elements in the array.
60
+     * example : middleWay([1, 2, 3], [4,5,6,2]); // Should return [2,11]
61
+     *           middleWay([5, 1, 2, 9], [3, 4, 5, 5]); // Should return [3, 9]
62
+     */
63
+    public Integer[] middleWay(Integer[] input1, Integer[] input2){
64
+        return null;
65
+    }
66
+
67
+
68
+    /**
69
+     * Start with 2 int arrays, a and b, each length 2.
70
+     * Consider the sum of the values in each array.
71
+     * Return the array which has the largest sum. In event of a tie, return a.
72
+     */
73
+    public Integer[] biggerTwo(Integer[] a, Integer[] b){
74
+        return null;
75
+    }
76
+}

+ 185
- 0
src/test/java/io/zipcoder/ArrayDrillsTest.java Ver fichero

@@ -0,0 +1,185 @@
1
+package io.zipcoder;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class ArrayDrillsTest {
8
+    private ArrayDrills arrayDrills;
9
+
10
+    @Before
11
+    public void setup(){
12
+        this.arrayDrills = new ArrayDrills();
13
+    }
14
+
15
+    @Test
16
+    public void firstLastTest1(){
17
+        Integer inputValue = 6;
18
+        Integer[] inputArray = {6,1,2,3};
19
+        Boolean actual = arrayDrills.firstLast(inputValue, inputArray);
20
+        Assert.assertTrue(actual);
21
+    }
22
+
23
+    @Test
24
+    public void firstLastTest2(){
25
+        Integer inputValue = 6;
26
+        Integer[] inputArray = {1,2,6};
27
+        Boolean actual = arrayDrills.firstLast(inputValue, inputArray);
28
+        Assert.assertTrue(actual);
29
+    }
30
+
31
+    @Test
32
+    public void firstLastTest3(){
33
+        Integer inputValue = 8;
34
+        Integer[] inputArray = {6,1,2,2};
35
+        Boolean actual = arrayDrills.firstLast(inputValue, inputArray);
36
+        Assert.assertFalse(actual);
37
+    }
38
+
39
+    @Test
40
+    public void sameFirstLastTest1(){
41
+        Integer[] inputArray = {6,1,2,2};
42
+        Boolean actual = arrayDrills.sameFirstLast(inputArray);
43
+        Assert.assertFalse(actual);
44
+    }
45
+
46
+    @Test
47
+    public void sameFirstLastTest2(){
48
+        Integer[] inputArray = {6,1,2,6};
49
+        Boolean actual = arrayDrills.sameFirstLast(inputArray);
50
+        Assert.assertTrue(actual);
51
+    }
52
+
53
+    @Test
54
+    public void sameFirstLastTest3(){
55
+        Integer[] inputArray = {1,1};
56
+        Boolean actual = arrayDrills.sameFirstLast(inputArray);
57
+        Assert.assertTrue(actual);
58
+    }
59
+
60
+    @Test
61
+    public void commonEndTest1(){
62
+        Integer[] inputArray1 = {1,2,3};
63
+        Integer[] inputArray2 = {7,3};
64
+        Boolean actual = arrayDrills.commonEnd(inputArray1, inputArray2);
65
+        Assert.assertTrue(actual);
66
+    }
67
+
68
+    @Test
69
+    public void commonEndTest2(){
70
+        Integer[] inputArray1 = {1,2,3};
71
+        Integer[] inputArray2 = {7,3,2};
72
+        Boolean actual = arrayDrills.commonEnd(inputArray1, inputArray2);
73
+        Assert.assertFalse(actual);
74
+    }
75
+
76
+    @Test
77
+    public void commonEndTest3(){
78
+        Integer[] inputArray1 = {1,2,3};
79
+        Integer[] inputArray2 = {1,3};
80
+        Boolean actual = arrayDrills.commonEnd(inputArray1, inputArray2);
81
+        Assert.assertTrue(actual);
82
+    }
83
+
84
+    @Test
85
+    public void rotateLeftTest1(){
86
+        Integer[] inputArray = {1,2,3};
87
+        Integer[] expected = {2,3,1};
88
+        Integer[] actual = arrayDrills.rotateLeft(inputArray);
89
+        Assert.assertArrayEquals(expected, actual);
90
+    }
91
+
92
+    @Test
93
+    public void rotateLeftTest2(){
94
+        Integer[] inputArray = {5,11,9};
95
+        Integer[] expected = {11,9,5};
96
+        Integer[] actual = arrayDrills.rotateLeft(inputArray);
97
+        Assert.assertArrayEquals(expected, actual);
98
+    }
99
+
100
+    @Test
101
+    public void rotateLeftTest3(){
102
+        Integer[] inputArray = {7,0,0};
103
+        Integer[] expected = {0,0,7};
104
+        Integer[] actual = arrayDrills.rotateLeft(inputArray);
105
+        Assert.assertArrayEquals(expected, actual);
106
+    }
107
+
108
+    @Test
109
+    public void maxValueTest1(){
110
+        Integer[] inputArray = {1,2,3};
111
+        Integer[] expected = {3,3,3};
112
+        Integer[] actual = arrayDrills.maxValue(inputArray);
113
+        Assert.assertArrayEquals(expected, actual);
114
+    }
115
+
116
+    @Test
117
+    public void maxValueTest2(){
118
+        Integer[] inputArray = {5,11,9,34,2};
119
+        Integer[] expected = {34,34,34,34,34};
120
+        Integer[] actual = arrayDrills.maxValue(inputArray);
121
+        Assert.assertArrayEquals(expected, actual);
122
+    }
123
+
124
+    @Test
125
+    public void maxValueTest3(){
126
+        Integer[] inputArray = {2,11,3};
127
+        Integer[] expected = {11,11,11};
128
+        Integer[] actual = arrayDrills.maxValue(inputArray);
129
+        Assert.assertArrayEquals(expected, actual);
130
+    }
131
+
132
+    @Test
133
+    public void middleWayTest1(){
134
+        Integer[] inputArray1 = {1,2,3};
135
+        Integer[] inputArray2 = {4,5,6,2};
136
+        Integer[] expected = {2,11};
137
+        Integer[] actual = arrayDrills.middleWay(inputArray1, inputArray2);
138
+        Assert.assertArrayEquals(expected, actual);
139
+    }
140
+
141
+    @Test
142
+    public void middleWayTest2(){
143
+        Integer[] inputArray1 = {5,1,2,9};
144
+        Integer[] inputArray2 = {3,4,5,5};
145
+        Integer[] expected = {3,9};
146
+        Integer[] actual = arrayDrills.middleWay(inputArray1, inputArray2);
147
+        Assert.assertArrayEquals(expected, actual);
148
+    }
149
+
150
+    @Test
151
+    public void middleWayTest3(){
152
+        Integer[] inputArray1 = {5,6,7,4,5};
153
+        Integer[] inputArray2 = {2,33,4,5,5};
154
+        Integer[] expected = {7,4};
155
+        Integer[] actual = arrayDrills.middleWay(inputArray1, inputArray2);
156
+        Assert.assertArrayEquals(expected, actual);
157
+    }
158
+
159
+    @Test
160
+    public void biggerTwo1(){
161
+        Integer[] inputArray1 = {5,6};
162
+        Integer[] inputArray2 = {2,33};
163
+        Integer[] expected = {2,33};
164
+        Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
165
+        Assert.assertArrayEquals(expected, actual);
166
+    }
167
+
168
+    @Test
169
+    public void biggerTwo2(){
170
+        Integer[] inputArray1 = {12, 12};
171
+        Integer[] inputArray2 = {12,12};
172
+        Integer[] expected = {12,12};
173
+        Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
174
+        Assert.assertArrayEquals(expected, actual);
175
+    }
176
+
177
+    @Test
178
+    public void biggerTwo3(){
179
+        Integer[] inputArray1 = {-1 ,20};
180
+        Integer[] inputArray2 = {2, 15};
181
+        Integer[] expected = {1,20};
182
+        Integer[] actual = arrayDrills.biggerTwo(inputArray1, inputArray2);
183
+        Assert.assertArrayEquals(expected, actual);
184
+    }
185
+}