Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add Spock Sample

  • Loading branch information...
commit 71123211bc4d9a36d7fdd6a729580a834219ec6b 1 parent 9d0534b
@tkdysk authored
View
38 GroovySample/src/main/java/smartcode/theme10/HashTableModoki.groovy
@@ -0,0 +1,38 @@
+package smartcode.theme10
+
+class HashTableModoki {
+ Object[] objArray = new Object[1000]
+
+ def getCustomHash(Object key){
+ if (key==null) return 0
+ return Math.abs(key.hashCode()) % 1000
+ }
+
+ def set(Object key, Object value) {
+ def defValues = objArray[getCustomHash(key)]
+ def values = []
+ if (defValues!=null) {
+ values = defValues
+ for (Object obj : values) {
+ Object defKey = ((Object[]) obj)[0]
+ if ((key==null && defKey==null) || key.equals(defKey)) {
+ values.remove(obj)
+ break
+ }
+ }
+ }
+ values << [key, value]
+ objArray[getCustomHash(key)] = values
+ }
+
+ def get(Object key){
+ def values = objArray[getCustomHash(key)]
+ for (Object obj : values) {
+ Object defKey = ((Object[]) obj)[0]
+ if ((key==null && defKey==null) || key.equals(defKey)) {
+ return ((Object[]) obj)[1]
+ }
+ }
+ return null
+ }
+}
View
31 GroovySample/src/test/java/sample/spock/SpockSample.groovy
@@ -1,31 +0,0 @@
-package sample.spock;
-
-import artistlist.GestArtistRank;
-import spock.lang.Specification;
-
-class EmptyStack extends Specification {
- def stack = new Stack()
-
- def "size"() {
- expect: stack.size() == 0
- }
-
- def "pop"() {
- when: stack.pop()
- then: thrown(EmptyStackException)
- }
-
- def "peek"() {
- when: stack.peek()
- then: thrown(EmptyStackException)
- }
-
- def "push"() {
- when:
- stack.push("elem")
-
- then:
- stack.size() == 1
- stack.peek() == "elem"
- }
-}
View
32 GroovySample/src/test/java/smartcode/theme10/HashTableModokiTest.groovy
@@ -0,0 +1,32 @@
+package smartcode.theme10;
+
+import spock.lang.Specification;
+
+class CustomHashTableTest extends Specification {
+ HashTableModoki target = new HashTableModoki()
+
+ def setup(){
+ target.set("key1", "value1")
+ target.set("", "value2")
+ target.set(null, "value3")
+ target.set(100, "value4")
+ target.set(0.9, "value5")
+ target.set(true, "value6")
+ target.set(null, "value7")
+ }
+
+ def "HashTableModoki Test"() {
+ expect:
+ target.get(key) == value
+
+ where:
+ key | value
+ "key1" | "value1"
+ "" | "value2"
+ 100 | "value4"
+ 0.9 | "value5"
+ true | "value6"
+ null | "value7"
+ "null" | null
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.