pysaumont / fpinkotlin Goto Github PK
View Code? Open in Web Editor NEWExercises and solutions for my book The Joy of Kotlin
Exercises and solutions for my book The Joy of Kotlin
In the description of how to run a single test you have
gradle :fpinkotlin-advancedlisthandling-exercises:test --tests com.fpinkotlin.advancedlisthandling.exercise01.ListTest
However, when I run this command without making any modifications to the projects (don't implement the required functionality) I don't get an error. Apparently, this is because the given test doesn't exist. If, instead, I run:
gradle :fpinkotlin-advancedlisthandling-exercises:test --tests com.fpinkotlin.advancedlisthandling.exercise02.ListTest
I do, indeed, see an error (note the use of exercise02
instead of exercise01
).
With the commited ( fpinkotlin/fpinkotlin-parent/gradle/wrapper/gradle-wrapper.properties
) version 2.2.1 of gradle-wrapper I get the following error if I try to build the project:
Failed to notify project evaluation listener.
org.gradle.api.Project.getPluginManager()Lorg/gradle/api/plugins/PluginManager;
org.gradle.api.Project.getPluginManager()Lorg/gradle/api/plugins/PluginManager;
If I updated the version to 4.6 everything works fine
Since I updated IntelliJ Idea to version 2019.1 I cannot run any test. The little green icon before the name of the class is no longer visible.
Hi @pysaumont,
I have imported the project as per the README, but I'm not able to run any tests both in Intellij and in using command line.
Im using:
Gradle 5.4.1
Intellij 2019.1.3
Currently the test for exercise 4.1 will run with negative Ints. The exercise asks for a function "add" that works on positive Ints.
Since the test generates cases with negative Ints you could either end up with a stack overflow or a never ending function (depending on implementation).
The solution to add two numbers is incorrect and works purely by accident only because types of both inputs are Int. If one of them is changed to Long, the answers would be incorrect. Also very simple addition like add(3, -3)
will result in a stackoverflow if the function is not marked tailrec because it takes 2^32 - 3
iterations to get b from -3 to 0.
Provided solution is tailrec fun add(x: Int, y: Int): Int = if (y == 0) x else add(inc(x), dec(y))
.
The correct solution would be
tailrec fun add(a: Int, b: Int): Int =
when {
(b == 0) -> a
(b > 0) -> add(inc(a), dec(b))
else -> add(dec(a), inc(b))
}
At the current state of the project the build will fail with installed JDK 14 (I use Adopt Open JDK 14).
This seems to be a known Bug of Gradle.
I used this simple workaround described in the comments here.
Just change the file \fpinkotlin\fpinkotlin-parent\gradle\wrapper\gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
# ^
# 6 instead of 1 to upgrade the version of Gradle
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
After this change the project compiles.
Hi @pysaumont Can you please explain why you removed Gradle wrapper from the repo?
The test for this exercise may be insufficient because it passes the case where the fibonacci stream produces only zeros.
z + y == x
will always be true when z, x, y are 0. But this sequence isn't fibonacci.
The test com.fpinkotlin.recursion.exercise07.ReverseTes
t points to com.fpinkotlin.recursion.exercise08.ReverseKt#reverse
and vice-versa
Exercise 4.9
I think the problem is that List is limited in size by the range of Int, whereas the test attempts to create a List whose size can be double the range of Int e.g. range(-2147483648, 2147483647)
.
The test always fails because there are missing parentheses here:
Factorial.factorial(n + 1) == Factorial.factorial(n) * (n + 1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.