From 4762facff21bd64ebe36b6c9018cd4cfc86d816a Mon Sep 17 00:00:00 2001 From: aksharma2 Date: Wed, 2 Aug 2017 12:02:27 +0800 Subject: [PATCH 1/4] modified config file --- koans/app/config/PathToEnlightenment.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/koans/app/config/PathToEnlightenment.xml b/koans/app/config/PathToEnlightenment.xml index dd104446..9f221929 100755 --- a/koans/app/config/PathToEnlightenment.xml +++ b/koans/app/config/PathToEnlightenment.xml @@ -31,14 +31,14 @@ - + - + + From dfa18b90e97b3da816a8c932fde99b8feb3f492b Mon Sep 17 00:00:00 2001 From: aksharma2 Date: Wed, 2 Aug 2017 12:13:00 +0800 Subject: [PATCH 2/4] modified config file --- koans/src/advanced/AboutMocks.java | 46 ------ koans/src/intermediate/AboutLocale.java | 50 ------- koans/src/java7/AboutDiamondOperator.java | 36 ----- .../java7/AboutJava7LiteralsEnhancements.java | 44 ------ koans/src/java7/AboutRequireNotNull.java | 46 ------ koans/src/java7/AboutStringsInSwitch.java | 30 ---- koans/src/java7/AboutTryWithResources.java | 109 -------------- koans/src/java8/AboutBase64.java | 40 ------ koans/src/java8/AboutDefaultMethods.java | 47 ------ koans/src/java8/AboutLambdas.java | 90 ------------ koans/src/java8/AboutLocalTime.java | 26 ---- koans/src/java8/AboutMultipleInheritance.java | 37 ----- koans/src/java8/AboutOptional.java | 39 ----- koans/src/java8/AboutStreams.java | 135 ------------------ 14 files changed, 775 deletions(-) delete mode 100755 koans/src/advanced/AboutMocks.java delete mode 100644 koans/src/intermediate/AboutLocale.java delete mode 100644 koans/src/java7/AboutDiamondOperator.java delete mode 100644 koans/src/java7/AboutJava7LiteralsEnhancements.java delete mode 100644 koans/src/java7/AboutRequireNotNull.java delete mode 100644 koans/src/java7/AboutStringsInSwitch.java delete mode 100644 koans/src/java7/AboutTryWithResources.java delete mode 100644 koans/src/java8/AboutBase64.java delete mode 100644 koans/src/java8/AboutDefaultMethods.java delete mode 100644 koans/src/java8/AboutLambdas.java delete mode 100644 koans/src/java8/AboutLocalTime.java delete mode 100644 koans/src/java8/AboutMultipleInheritance.java delete mode 100644 koans/src/java8/AboutOptional.java delete mode 100644 koans/src/java8/AboutStreams.java diff --git a/koans/src/advanced/AboutMocks.java b/koans/src/advanced/AboutMocks.java deleted file mode 100755 index fd03e982..00000000 --- a/koans/src/advanced/AboutMocks.java +++ /dev/null @@ -1,46 +0,0 @@ -package advanced; - -import com.sandwich.koan.Koan; - -import static com.sandwich.util.Assert.fail; - -public class AboutMocks { - - static interface Collaborator { - public void doBusinessStuff(); - } - - static class ExplosiveCollaborator implements Collaborator { - public void doBusinessStuff() { - fail("Default collaborator's behavior is complicating testing."); - } - } - - static class ClassUnderTest { - Collaborator c; - - public ClassUnderTest() { - // default is to pass a broken Collaborator, test should pass one - // that doesn't throw exception - this(new ExplosiveCollaborator()); - } - - public ClassUnderTest(Collaborator c) { - this.c = c; - } - - public boolean doSomething() { - c.doBusinessStuff(); - return true; - } - } - - @Koan - public void simpleAnonymousMock() { - // HINT: pass a safe Collaborator implementation to constructor - // new ClassUnderTest(new Collaborator(){... it should not be the - // objective of this test to test that collaborator, so replace it - new ClassUnderTest().doSomething(); - } - -} diff --git a/koans/src/intermediate/AboutLocale.java b/koans/src/intermediate/AboutLocale.java deleted file mode 100644 index 48729987..00000000 --- a/koans/src/intermediate/AboutLocale.java +++ /dev/null @@ -1,50 +0,0 @@ -package intermediate; - -import com.sandwich.koan.Koan; - -import java.text.DateFormat; -import java.text.NumberFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.Locale; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutLocale { - - @Koan - public void localizedOutputOfDates() { - Calendar cal = Calendar.getInstance(); - cal.set(2011, 3, 3); - Date date = cal.getTime(); - Locale localeBR = new Locale("pt", "BR"); // portuguese, Brazil - DateFormat dateformatBR = DateFormat.getDateInstance(DateFormat.FULL, localeBR); - assertEquals(dateformatBR.format(date), __); - - Locale localeJA = new Locale("ja"); // Japan - DateFormat dateformatJA = DateFormat.getDateInstance(DateFormat.FULL, localeJA); - // Well if you don't know how to type these characters, try "de", "it" or "us" ;-) - assertEquals(dateformatJA.format(date), __); - } - - @Koan - public void getCountryInformation() { - Locale locBR = new Locale("pt", "BR"); - assertEquals(locBR.getDisplayCountry(), __); - assertEquals(locBR.getDisplayCountry(locBR), __); - - Locale locCH = new Locale("it", "CH"); - assertEquals(locCH.getDisplayCountry(), __); - assertEquals(locCH.getDisplayCountry(locCH), __); - assertEquals(locCH.getDisplayCountry(new Locale("de", "CH")), __); - } - - @Koan - public void formatCurrency() { - float someAmount = 442.23f; // Don't use floats for money in real life. Really. It's a bad idea. - Locale locBR = new Locale("pt", "BR"); - NumberFormat nf = NumberFormat.getCurrencyInstance(locBR); - assertEquals(nf.format(someAmount), __); - } -} diff --git a/koans/src/java7/AboutDiamondOperator.java b/koans/src/java7/AboutDiamondOperator.java deleted file mode 100644 index a9c32ac0..00000000 --- a/koans/src/java7/AboutDiamondOperator.java +++ /dev/null @@ -1,36 +0,0 @@ -package java7; - -import com.sandwich.koan.Koan; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutDiamondOperator { - - @Koan - public void diamondOperator() { - String[] animals = {"Dog", "Cat", "Tiger", "Elephant", "Zebra"}; - //Generic type of array list inferred - empty <> operator - List animalsList = new ArrayList<>(Arrays.asList(animals)); - assertEquals(animalsList, __); - } - - @Koan - public void diamondOperatorInMethodCall() { - String[] animals = {"Dog", "Cat", "Tiger", "Elephant", "Zebra"}; - //type of new ArrayList<>() inferred from method parameter - List animalsList = fill(new ArrayList<>()); - assertEquals(animalsList, __); - } - - private List fill(List list) { - String[] animals = {"Dog", "Cat", "Tiger", "Elephant", "Zebra"}; - list.addAll(Arrays.asList(animals)); - return list; - } - -} diff --git a/koans/src/java7/AboutJava7LiteralsEnhancements.java b/koans/src/java7/AboutJava7LiteralsEnhancements.java deleted file mode 100644 index 4d8e2a38..00000000 --- a/koans/src/java7/AboutJava7LiteralsEnhancements.java +++ /dev/null @@ -1,44 +0,0 @@ -package java7; - -import com.sandwich.koan.Koan; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutJava7LiteralsEnhancements { - - @Koan - public void binaryLiterals() { - //binary literals are marked with 0b prefix - short binaryLiteral = 0b1111; - assertEquals(binaryLiteral, __); - } - - @Koan - public void binaryLiteralsWithUnderscores() { - //literals can use underscores for improved readability - short binaryLiteral = 0b1111_1111; - assertEquals(binaryLiteral, __); - } - - @Koan - public void numericLiteralsWithUnderscores() { - long literal = 111_111_111L; - //notice capital "B" - a valid binary literal prefix - short multiplier = 0B1_000; - assertEquals(literal * multiplier, __); - } - - @Koan - public void negativeBinaryLiteral() { - int negativeBinaryLiteral = 0b1111_1111_1111_1111_1111_1111_1111_1100 / 4; - assertEquals(negativeBinaryLiteral, __); - } - - @Koan - public void binaryLiteralsWithBitwiseOperator() { - int binaryLiteral = ~0b1111_1111; - assertEquals(binaryLiteral, __); - } - -} diff --git a/koans/src/java7/AboutRequireNotNull.java b/koans/src/java7/AboutRequireNotNull.java deleted file mode 100644 index de4b017f..00000000 --- a/koans/src/java7/AboutRequireNotNull.java +++ /dev/null @@ -1,46 +0,0 @@ -package java7; - -import com.sandwich.koan.Koan; - -import java.util.Objects; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutRequireNotNull { - - @Koan - public void failArgumentValidationWithRequireNotNull() { - // This koan demonstrates the use of Objects.requireNotNull - // in place of traditional argument validation using exceptions - String s = ""; - try { - s += validateUsingRequireNotNull(null); - } catch (NullPointerException ex) { - s = "caught a NullPointerException"; - } - assertEquals(s, __); - } - - @Koan - public void passArgumentValidationWithRequireNotNull() { - // This koan demonstrates the use of Objects.requireNotNull - // in place of traditional argument validation using exceptions - String s = ""; - try { - s += validateUsingRequireNotNull("valid"); - } catch (NullPointerException ex) { - s = "caught a NullPointerException"; - } - assertEquals(s, __); - } - - private int validateUsingRequireNotNull(String str) { - // If you're only concerned with null values requireNotNull - // is concise and the point of the NullPointerException it - // throws is clear, though you can optionally provide a - // description as well - return Objects.requireNonNull(str).length(); - } - -} diff --git a/koans/src/java7/AboutStringsInSwitch.java b/koans/src/java7/AboutStringsInSwitch.java deleted file mode 100644 index 31a79c6f..00000000 --- a/koans/src/java7/AboutStringsInSwitch.java +++ /dev/null @@ -1,30 +0,0 @@ -package java7; - -import com.sandwich.koan.Koan; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutStringsInSwitch { - - @Koan - public void stringsInSwitchStatement() { - String[] animals = {"Dog", "Cat", "Tiger", "Elephant", "Zebra"}; - String dangerous = null; - String notDangerous = null; - for (String animal : animals) { - switch (animal) { - case "Tiger": - dangerous = animal; - case "Dog": - case "Cat": - case "Elephant": - case "Zebra": - notDangerous = animal; - } - } - assertEquals(notDangerous, __); - assertEquals(dangerous, __); - } - -} diff --git a/koans/src/java7/AboutTryWithResources.java b/koans/src/java7/AboutTryWithResources.java deleted file mode 100644 index 4934b1e1..00000000 --- a/koans/src/java7/AboutTryWithResources.java +++ /dev/null @@ -1,109 +0,0 @@ -package java7; - -import com.sandwich.koan.Koan; - -import java.io.*; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutTryWithResources { - - class AutoClosableResource implements AutoCloseable { - public void foo() throws WorkException { - throw new WorkException("Exception thrown while working"); - } - - public void close() throws CloseException { - throw new CloseException("Exception thrown while closing"); - } - } - - class WorkException extends Exception { - public WorkException(String message) { - super(message); - } - } - - class CloseException extends Exception { - public CloseException(String message) { - super(message); - } - } - - @Koan - public void lookMaNoClose() { - String str = "first line" - + System.lineSeparator() - + "second line"; - InputStream is = new ByteArrayInputStream(str.getBytes()); - String line; - /* BufferedReader implementing @see java.lang.AutoCloseable interface */ - try (BufferedReader br = - new BufferedReader( - new InputStreamReader(is))) { - line = br.readLine(); - //br guaranteed to be closed - } catch (IOException e) { - line = "error"; - } - assertEquals(line, __); - } - - @Koan - public void lookMaNoCloseWithException() throws IOException { - String line = "no need to close readers"; - try (BufferedReader br = - new BufferedReader( - new FileReader("I do not exist!"))) { - line = br.readLine(); - } catch (FileNotFoundException e) { - line = "no more leaking!"; - } - assertEquals(line, __); - } - - @Koan - public void lookMaNoCloseWithMultipleResources() throws IOException { - String str = "first line" - + System.lineSeparator() - + "second line"; - InputStream is = new ByteArrayInputStream(str.getBytes()); - String line; - //multiple resources in the same try declaration - try (BufferedReader br = - new BufferedReader( - new FileReader("I do not exist!")); - BufferedReader brFromString = - new BufferedReader( - new InputStreamReader(is)) - ) { - line = br.readLine(); - line += brFromString.readLine(); - } catch (IOException e) { - line = "error"; - } - assertEquals(line, __); - } - - @Koan - public void supressException() { - String message = ""; - try { - bar(); - } catch (WorkException e) { - message += e.getMessage() + " " + e.getSuppressed()[0].getMessage(); - } catch (CloseException e) { - message += e.getMessage(); - } - assertEquals(message, __); - } - - - public void bar() throws CloseException, WorkException { - try (AutoClosableResource autoClosableResource = - new AutoClosableResource()) { - autoClosableResource.foo(); - } - } -} \ No newline at end of file diff --git a/koans/src/java8/AboutBase64.java b/koans/src/java8/AboutBase64.java deleted file mode 100644 index ed1235e8..00000000 --- a/koans/src/java8/AboutBase64.java +++ /dev/null @@ -1,40 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import java.util.Base64; -import java.io.UnsupportedEncodingException; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutBase64 { - - private final String plainText = "lorem ipsum"; - private final String encodedText = "bG9yZW0gaXBzdW0="; - - @Koan - public void base64Encoding() { - try { - // Encode the plainText - // This uses the basic Base64 encoding scheme but there are corresponding - // getMimeEncoder and getUrlEncoder methods available if you require a - // different format/Base64 Alphabet - assertEquals(encodedText, Base64.getEncoder().encodeToString(__.getBytes("utf-8"))); - } catch (UnsupportedEncodingException ex) {} - } - - @Koan - public void base64Decoding() { - // Decode the Base64 encodedText - // This uses the basic Base64 decoding scheme but there are corresponding - // getMimeDecoder and getUrlDecoder methods available if you require a - // different format/Base64 Alphabet - byte[] decodedBytes = Base64.getDecoder().decode(__); - try { - String decodedText = new String(decodedBytes, "utf-8"); - assertEquals(plainText, decodedText); - } catch (UnsupportedEncodingException ex) {} - } - -} diff --git a/koans/src/java8/AboutDefaultMethods.java b/koans/src/java8/AboutDefaultMethods.java deleted file mode 100644 index d2a5c994..00000000 --- a/koans/src/java8/AboutDefaultMethods.java +++ /dev/null @@ -1,47 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutDefaultMethods { - - @Koan - public void interfaceDefaultMethod() { - StringUtil stringUtil = new StringUtil() { - @Override - public String reverse(String s) { - return new StringBuilder(s).reverse().toString(); - } - }; - String capitalizedReversed = stringUtil.capitalize( - stringUtil.reverse("gnirut")); - assertEquals(capitalizedReversed, __); - } - - @Koan - public void interfaceStaticMethod() { - assertEquals(StringUtil.enclose("me"), __); - } - - interface StringUtil { - - //static method in interface - static String enclose(String in) { - return "[" + in + "]"; - } - - String reverse(String s); - - //interface can contain non-abstract method implementations marked by "default" keyword - default String capitalize(String s) { - return s.toUpperCase(); - } - - default String capitalizeFirst(String s) { - return s.substring(0, 1).toUpperCase() + s.substring(1); - } - } - -} diff --git a/koans/src/java8/AboutLambdas.java b/koans/src/java8/AboutLambdas.java deleted file mode 100644 index 8cab569b..00000000 --- a/koans/src/java8/AboutLambdas.java +++ /dev/null @@ -1,90 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import java.util.function.Function; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutLambdas { - - interface Caps { - public String capitalize(String name); - } - - String fieldFoo = "Lambdas"; - - @Override - public String toString() { - return "CAPS"; - } - - static String str = ""; - - //lambda has access to "this" - Caps thisLambdaField = s -> this.toString(); - //lambda has access to object methods - Caps toStringLambdaField = s -> toString(); - - @Koan - public void verySimpleLambda() throws InterruptedException { - Runnable r8 = () -> str = "changed in lambda"; - r8.run(); - assertEquals(str, __); - } - - @Koan - public void simpleLambda() { - Caps caps = (String n) -> { - return n.toUpperCase(); - }; - String capitalized = caps.capitalize("James"); - assertEquals(capitalized, __); - } - - @Koan - public void simpleSuccinctLambda() { - //parameter type can be omitted, - //code block braces {} and return statement can be omitted for single statement lambda - //parameter parenthesis can be omitted for single parameter lambda - Caps caps = s -> s.toUpperCase(); - String capitalized = caps.capitalize("Arthur"); - assertEquals(capitalized, __); - } - - @Koan - public void lambdaField() { - assertEquals(thisLambdaField.capitalize(""), __); - } - - @Koan - public void lambdaField2() { - assertEquals(toStringLambdaField.capitalize(""), __); - } - - @Koan - public void effectivelyFinal() { - //final can be omitted like this: - /* final */ - String effectivelyFinal = "I'm effectively final"; - Caps caps = s -> effectivelyFinal.toUpperCase(); - assertEquals(caps.capitalize(effectivelyFinal), __); - } - - @Koan - public void methodReference() { - Caps caps = String::toUpperCase; - String capitalized = caps.capitalize("Gosling"); - assertEquals(capitalized, __); - } - - @Koan - public void thisIsSurroundingClass() { - //"this" in lambda points to surrounding class - Function foo = s -> s + this.fieldFoo + s; - assertEquals(foo.apply("|"), __); - } - -} - diff --git a/koans/src/java8/AboutLocalTime.java b/koans/src/java8/AboutLocalTime.java deleted file mode 100644 index c99e1dc1..00000000 --- a/koans/src/java8/AboutLocalTime.java +++ /dev/null @@ -1,26 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import java.time.LocalTime; -import java.time.temporal.ChronoUnit; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutLocalTime { - - @Koan - public void localTime() { - LocalTime t1 = LocalTime.of(7, 30); - assertEquals(t1, LocalTime.parse(__)); - } - - @Koan - public void localTimeMinus() { - LocalTime t1 = LocalTime.parse("10:30"); - LocalTime t2 = t1.minus(2, ChronoUnit.HOURS); - assertEquals(t2, LocalTime.parse(__)); - } - -} diff --git a/koans/src/java8/AboutMultipleInheritance.java b/koans/src/java8/AboutMultipleInheritance.java deleted file mode 100644 index 40a54c56..00000000 --- a/koans/src/java8/AboutMultipleInheritance.java +++ /dev/null @@ -1,37 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutMultipleInheritance { - - interface Human { - default String sound() { - return "hello"; - } - } - - interface Bull { - default String sound() { - return "moo"; - } - } - - class Minotaur implements Human, Bull { - //both interfaces implement same default method - //has to be overridden - @Override - public String sound() { - return Bull.super.sound(); - } - } - - @Koan - public void multipleInheritance() { - Minotaur minotaur = new Minotaur(); - assertEquals(minotaur.sound(), __); - } - -} diff --git a/koans/src/java8/AboutOptional.java b/koans/src/java8/AboutOptional.java deleted file mode 100644 index d2ba6b53..00000000 --- a/koans/src/java8/AboutOptional.java +++ /dev/null @@ -1,39 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import java.util.Optional; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutOptional { - - boolean optionalIsPresentField = false; - - @Koan - public void isPresent() { - boolean optionalIsPresent = false; - Optional value = notPresent(); - if (value.isPresent()) { - optionalIsPresent = true; - } - assertEquals(optionalIsPresent, __); - } - - @Koan - public void ifPresentLambda() { - Optional value = notPresent(); - value.ifPresent(x -> optionalIsPresentField = true); - assertEquals(optionalIsPresentField, __); - } - - //use optional on api to signal that value is optional - public Optional notPresent() { - return Optional.empty(); - } - - private Optional present() { - return Optional.of("is present"); - } -} diff --git a/koans/src/java8/AboutStreams.java b/koans/src/java8/AboutStreams.java deleted file mode 100644 index 42e7b2db..00000000 --- a/koans/src/java8/AboutStreams.java +++ /dev/null @@ -1,135 +0,0 @@ -package java8; - -import com.sandwich.koan.Koan; - -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutStreams { - - String str = ""; - - List places = Arrays.asList("Belgrade", "Zagreb", "Sarajevo", "Skopje", "Ljubljana", "Podgorica"); - - @Koan - public void simpleCount() { - long count = places.stream().count(); - assertEquals(count, __); - } - - @Koan - public void filteredCount() { - long count = places.stream() - .filter(s -> s.startsWith("S")) - .count(); - assertEquals(count, __); - } - - @Koan - public void max() { - String longest = places.stream() - .max(Comparator.comparing(cityName -> cityName.length())) - .get(); - assertEquals(longest, __); - } - - @Koan - public void min() { - String shortest = places.stream() - .min(Comparator.comparing(cityName -> cityName.length())) - .get(); - assertEquals(shortest, __); - } - - @Koan - public void reduce() { - String join = places.stream() - .reduce("", String::concat); - assertEquals(join, __); - } - - @Koan - public void reduceWithoutStarterReturnsOptional() { - Optional join = places.stream() - .reduce(String::concat); - assertEquals(join.get(), __); - } - - @Koan - public void join() { - String join = places.stream() - .reduce((accumulated, cityName) -> accumulated + "\", \"" + cityName) - .get(); - assertEquals(join, __); - } - - @Koan - public void reduceWithBinaryOperator() { - String join = places.stream() - .reduce("", String::concat); - assertEquals(join, __); - } - - @Koan - public void stringJoin() { - String join = places.stream() - .collect(Collectors.joining("\", \"")); - assertEquals(join, __); - } - - @Koan - public void mapReduce() { - OptionalDouble averageLengthOptional = places.stream() - .mapToInt(String::length) - .average(); - double averageLength = Math.round(averageLengthOptional.getAsDouble()); - assertEquals(averageLength, __); - } - - @Koan - public void parallelMapReduce() { - int lengthSum = places.parallelStream() - .mapToInt(String::length) - .sum(); - assertEquals(lengthSum, __); - } - - @Koan - public void limitSkip() { - int lengthSum_Limit_3_Skip_1 = places.stream() - .mapToInt(String::length) - .limit(3) - .skip(1) - .sum(); - assertEquals(lengthSum_Limit_3_Skip_1, __); - } - - @Koan - public void lazyEvaluation() { - Stream stream = places.stream() - .filter(s -> { - str = "hello"; - return s.startsWith("S"); - }); - assertEquals(str, __); - } - - @Koan - public void sumRange() { - int sum = IntStream.range(1, 4).sum(); - assertEquals(sum, __); - } - - @Koan - public void rangeToList() { - List range = IntStream.range(1, 4) - .boxed() - .collect(Collectors.toList()); - assertEquals(range, __); - } -} From 4a1bc164304a585b4fd61e4761d91eeb5745654b Mon Sep 17 00:00:00 2001 From: aksharma2 Date: Wed, 2 Aug 2017 13:10:08 +0800 Subject: [PATCH 3/4] updated koans --- .DS_Store | Bin 0 -> 6148 bytes koans/.DS_Store | Bin 0 -> 6148 bytes koans/app/config/PathToEnlightenment.xml | 10 +- koans/src/.DS_Store | Bin 0 -> 6148 bytes koans/src/beginner/.DS_Store | Bin 0 -> 6148 bytes koans/src/beginner/AboutBitwiseOperators.java | 24 -- koans/src/beginner/AboutExceptions.java | 166 ------------- koans/src/beginner/AboutPrimitives.java | 227 ------------------ koans/src/intermediate/.DS_Store | Bin 0 -> 6148 bytes koans/src/intermediate/AboutDates.java | 73 ------ koans/src/intermediate/AboutInnerClasses.java | 150 ------------ .../intermediate/AboutRegularExpressions.java | 57 ----- 12 files changed, 5 insertions(+), 702 deletions(-) create mode 100644 .DS_Store create mode 100644 koans/.DS_Store create mode 100644 koans/src/.DS_Store create mode 100644 koans/src/beginner/.DS_Store delete mode 100644 koans/src/beginner/AboutExceptions.java delete mode 100644 koans/src/beginner/AboutPrimitives.java create mode 100644 koans/src/intermediate/.DS_Store delete mode 100644 koans/src/intermediate/AboutDates.java delete mode 100644 koans/src/intermediate/AboutInnerClasses.java delete mode 100644 koans/src/intermediate/AboutRegularExpressions.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e3f751c150f9bfe54de0ac87c134d40c38e3aacb GIT binary patch literal 6148 zcmeHKyJ`bL3>?J{7}B^*xxbJgAO)m=6p#W^;CcnBmo6TzFCnHBkODWVfPWtv-LV&riSg;+5+eX{ z&Tts_F-s7e2Z+6JOk{*+NhK!LYQ(UlGu|q%7mkTZhsDjTQ#V^pC>FOf-Xa~=6SYbK zDR8d9ERRd?|IhRb^Zz+XCn+EWZb|{0uQ%%zU#WWQdF^gR7ES*H$5cmnB-G%I%Z zD|S`@Z2$T80!#olbXV*=%*>dt@PRwdU#I)^a=X5>;#J@&VrHyNnC;iLL0pQvfVyTmjO&;ssLc!1UOG})p;=82 zR;?Ceh}WZ?+UmMqI#RP8R>OzYoz15hnq@nzF`-!xQ4j$Um=RcIKKc27r2jVm&svm< zfC&6E0=7P!4tu^-ovjbA=k?dB`g+i*aXG_}p8zI)6mRKa+;6_1_R^8c3Qa!(fk8n8 H{*=HsM+*^= literal 0 HcmV?d00001 diff --git a/koans/app/config/PathToEnlightenment.xml b/koans/app/config/PathToEnlightenment.xml index 9f221929..5bb44be6 100755 --- a/koans/app/config/PathToEnlightenment.xml +++ b/koans/app/config/PathToEnlightenment.xml @@ -11,13 +11,13 @@ - + - + @@ -27,12 +27,12 @@ - + - + - + - - - + + + - - + + + + - - - - - - - - - - diff --git a/koans/src/intermediate/AboutAutoboxing.java b/koans/src/intermediate/AboutAutoboxing.java deleted file mode 100755 index 4063eb2d..00000000 --- a/koans/src/intermediate/AboutAutoboxing.java +++ /dev/null @@ -1,52 +0,0 @@ -package intermediate; - -import com.sandwich.koan.Koan; - -import java.util.ArrayList; -import java.util.List; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutAutoboxing { - - @Koan - public void addPrimitivesToCollection() { - List list = new ArrayList(); - list.add(0, new Integer(42)); - assertEquals(list.get(0), __); - } - - @Koan - public void addPrimitivesToCollectionWithAutoBoxing() { - List list = new ArrayList(); - list.add(0, 42); - assertEquals(list.get(0), __); - } - - @Koan - public void migrateYourExistingCodeToAutoBoxingWithoutFear() { - List list = new ArrayList(); - list.add(0, new Integer(42)); - assertEquals(list.get(0), __); - - list.add(1, 84); - assertEquals(list.get(1), __); - } - - @Koan - public void allPrimitivesCanBeAutoboxed() { - List doubleList = new ArrayList(); - doubleList.add(0, new Double(42)); - assertEquals(doubleList.get(0), __); - - List longList = new ArrayList(); - longList.add(0, new Long(42)); - assertEquals(longList.get(0), __); - - List characterList = new ArrayList(); - characterList.add(0, new Character('z')); - assertEquals(characterList.get(0), __); - } - -} diff --git a/koans/src/intermediate/AboutComparison.java b/koans/src/intermediate/AboutComparison.java deleted file mode 100644 index ee58ab64..00000000 --- a/koans/src/intermediate/AboutComparison.java +++ /dev/null @@ -1,83 +0,0 @@ -package intermediate; - -import com.sandwich.koan.Koan; - -import java.util.Arrays; -import java.util.Comparator; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutComparison { - - @Koan - public void compareObjects() { - String a = "abc"; - String b = "bcd"; - assertEquals(a.compareTo(b), __); - assertEquals(a.compareTo(a), __); - assertEquals(b.compareTo(a), __); - } - - static class Car implements Comparable { - int horsepower; - - // For an explanation for this implementation look at - // http://download.oracle.com/javase/6/docs/api/java/lang/Comparable.html#compareTo(T) - public int compareTo(Car o) { - return horsepower - o.horsepower; - } - - } - - @Koan - public void makeObjectsComparable() { - Car vwbeetle = new Car(); - vwbeetle.horsepower = 50; - Car porsche = new Car(); - porsche.horsepower = 300; - assertEquals(vwbeetle.compareTo(porsche), __); - } - - static class RaceHorse { - int speed; - int age; - - @Override - public String toString() { - return "Speed: " + speed + " Age: " + age; - } - } - - static class HorseSpeedComparator implements Comparator { - public int compare(RaceHorse o1, RaceHorse o2) { - return o1.speed - o2.speed; - } - } - - static class HorseAgeComparator implements Comparator { - public int compare(RaceHorse o1, RaceHorse o2) { - return o1.age - o2.age; - } - } - - @Koan - public void makeObjectsComparableWithoutComparable() { - RaceHorse lindy = new RaceHorse(); - lindy.age = 10; - lindy.speed = 2; - RaceHorse lightning = new RaceHorse(); - lightning.age = 2; - lightning.speed = 10; - RaceHorse slowy = new RaceHorse(); - slowy.age = 12; - slowy.speed = 1; - - RaceHorse[] horses = {lindy, slowy, lightning}; - - Arrays.sort(horses, new HorseAgeComparator()); - assertEquals(horses[0], __); - Arrays.sort(horses, new HorseSpeedComparator()); - assertEquals(horses[0], __); - } -} diff --git a/koans/src/intermediate/AboutEquality.java b/koans/src/intermediate/AboutEquality.java deleted file mode 100644 index f3f50e8e..00000000 --- a/koans/src/intermediate/AboutEquality.java +++ /dev/null @@ -1,128 +0,0 @@ -package intermediate; - -import com.sandwich.koan.Koan; - -import static com.sandwich.koan.constant.KoanConstants.__; -import static com.sandwich.util.Assert.assertEquals; - -public class AboutEquality { - // This suite of Koans expands on the concepts introduced in beginner.AboutEquality - - @Koan - public void sameObject() { - Object a = new Object(); - Object b = a; - assertEquals(a == b, __); - } - - @Koan - public void equalObject() { - Integer a = new Integer(1); - Integer b = new Integer(1); - assertEquals(a.equals(b), __); - assertEquals(b.equals(a), __); - } - - @Koan - public void noObjectShouldBeEqualToNull() { - assertEquals(new Object().equals(null), __); - } - - static class Car { - private String name = ""; - private int horsepower = 0; - - public Car(String s, int p) { - name = s; - horsepower = p; - } - - @Override - public boolean equals(Object other) { - // Change this implementation to match the equals contract - // Car objects with same horsepower and name values should be considered equal - // http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#equals(java.lang.Object) - return false; - } - - @Override - public int hashCode() { - // @see http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode() - return super.hashCode(); - } - } - - @Koan - public void equalForOwnObjects() { - Car car1 = new Car("Beetle", 50); - Car car2 = new Car("Beetle", 50); - // @see Car.equals (around line 45) for the place to solve this - assertEquals(car1.equals(car2), true); - assertEquals(car2.equals(car1), true); - } - - @Koan - public void unequalForOwnObjects() { - Car car1 = new Car("Beetle", 50); - Car car2 = new Car("Porsche", 300); - // @see Car.equals (around line 45) for the place to solve this - assertEquals(car1.equals(car2), false); - } - - @Koan - public void unequalForOwnObjectsWithDifferentType() { - Car car1 = new Car("Beetle", 50); - String s = "foo"; - // @see Car.equals (around line 45) for the place to solve this - assertEquals(car1.equals(s), false); - } - - @Koan - public void equalNullForOwnObjects() { - Car car1 = new Car("Beetle", 50); - // @see Car.equals (around line 45) for the place to solve this - assertEquals(car1.equals(null), false); - } - - @Koan - public void ownHashCode() { - // As a general rule: When you override equals you should override - // hash code - // Read the hash code contract to figure out why - // http://download.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode() - - // Implement Car.hashCode around line 51 so that the following assertions pass - Car car1 = new Car("Beetle", 50); - Car car2 = new Car("Beetle", 50); - assertEquals(car1.equals(car2), true); - assertEquals(car1.hashCode() == car2.hashCode(), true); - } - - static class Chicken { - String color = "green"; - - @Override - public int hashCode() { - return 4000; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Chicken)) - return false; - return ((Chicken) other).color.equals(color); - } - } - - @Koan - public void ownHashCodeImplementationPartTwo() { - Chicken chicken1 = new Chicken(); - chicken1.color = "black"; - Chicken chicken2 = new Chicken(); - assertEquals(chicken1.equals(chicken2), __); - assertEquals(chicken1.hashCode() == chicken2.hashCode(), __); - // Does this still fit the hashCode contract? Why (not)? - // Fix the Chicken class to correct this. - } - -}