This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 54089a0 general tidy up
54089a0 is described below
commit 54089a05866a8545f2315042a22661c3a840ca73
Author: Paul King <[email protected]>
AuthorDate: Fri Feb 17 15:09:16 2023 +1000
general tidy up
---
site/src/site/blog/parsing-json-with-groovy.adoc | 19 ++++-----
...olving-cryptarithmetic-puzzles-with-groovy.adoc | 16 ++++++++
.../site/blog/testing-your-java-with-groovy.adoc | 13 +++---
.../site/blog/working-with-sql-databases-with.adoc | 46 +++++++++++-----------
4 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/site/src/site/blog/parsing-json-with-groovy.adoc
b/site/src/site/blog/parsing-json-with-groovy.adoc
index 3bb9484..7a898ba 100644
--- a/site/src/site/blog/parsing-json-with-groovy.adoc
+++ b/site/src/site/blog/parsing-json-with-groovy.adoc
@@ -228,13 +228,13 @@ surefire plugin will use that by default and not find our
test.
Running the test should yield:
+[subs="quotes,macros"]
----
-[INFO] -------------------------------------------------------
-[INFO] T E S T S
-[INFO] -------------------------------------------------------
-[INFO] Running JsonTest
-[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.36 s
- in JsonTest
-Advanced features
+pass:v[[][blue]#INFO#] ------------------------------------------------------
+pass:v[[][blue]#INFO#] T E S T S
+pass:v[[][blue]#INFO#] ------------------------------------------------------
+pass:v[[][blue]#INFO#] Running JsonTest
+pass:v[[][blue]#INFO#] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time
elapsed: 0.36 s - in JsonTest
----
== Advanced features
@@ -315,7 +315,7 @@ GINQ or GQuery. We can use that with JSON too.
Suppose we have information in JSON format about fruits, their
prices (per 100g) and the concentration of vitamin C (per 100g):
-[source,groovy]
+[source,json]
----
{
"prices": [
@@ -347,13 +347,13 @@ when we go shopping. Our GQuery processing looks like
this:
----
def jsonFile = new File('fruit.json')
def json = new JsonSlurper().parse(jsonFile)
-assert GQ {
+assert GQL {
from p in json.prices
join c in json.vitC on c.name == p.name
orderby c.conc / p.price in desc
limit 2
select p.name
-}.toList() == ['Kakuda plum', 'Kiwifruit']
+} == ['Kakuda plum', 'Kiwifruit']
----
We can see, for this data, Kakadu plums followed by Kiwifruit
@@ -379,6 +379,7 @@ $ time groovy GroovyJsonIndexOverlay.groovy
real 0m1.365s
user 0m4.157s
sys 0m0.145s
+
$ time groovy GroovyJsonCharacterSource.groovy
real 0m1.447s
user 0m4.472s
diff --git
a/site/src/site/blog/solving-cryptarithmetic-puzzles-with-groovy.adoc
b/site/src/site/blog/solving-cryptarithmetic-puzzles-with-groovy.adoc
index cbb0b58..745af33 100644
--- a/site/src/site/blog/solving-cryptarithmetic-puzzles-with-groovy.adoc
+++ b/site/src/site/blog/solving-cryptarithmetic-puzzles-with-groovy.adoc
@@ -133,6 +133,18 @@ s = 9, e = 5, n = 6, d = 7
m = 1, o = 0, r = 8, y = 2
----
+== Using Constraint Programming
+
+For the brute force approaches, we had a condition which checked any
+potential candidate answer to see if it was a correct solution. We had
+to be very explicit in how we wanted the potential candidates to be
+created. For constraint programming, we instead define variables to
+represent the problem, any known bounds on those variables, and we
+specify any other known properties of the solution, which in our case
+will be something similar to the condition we had to check if the
+answer was correct previously. Let's examine how to do that with
+three libraries, one with a variation.
+
== Choco
Here is the code using the https://choco-solver.org/[Choco]
@@ -339,6 +351,8 @@ programming libraries seem to be using the direct library
classes.
Indeed, the version of the Choco implementation used by the JSR331
implementation is over 10 years old.
+=== Incorporating Carry
+
The scalar product global constraint we have used in the previous
examples is very powerful and probably would be our first choice
for this problem. We can, however, model constraint programming
@@ -393,6 +407,8 @@ They don't form part of the answer that interests us, so we
would
be free to just print out the part of the solution which interests
us if we wanted.
+=== Creating a DSL
+
The previous example has lots of calls to `add` and `mul` methods.
We can create a little bit of a DSL to provide some syntactic
sugar to our previous examples to allow use of Groovy's operator
diff --git a/site/src/site/blog/testing-your-java-with-groovy.adoc
b/site/src/site/blog/testing-your-java-with-groovy.adoc
index aa43ff2..dc04fa4 100644
--- a/site/src/site/blog/testing-your-java-with-groovy.adoc
+++ b/site/src/site/blog/testing-your-java-with-groovy.adoc
@@ -4,6 +4,7 @@ Paul King
:keywords: groovy, java, spock, testing, jqwik, pitest, junit, jacoco
:description: This post looks at testing Java using Groovy, Spock, JUnit5,
Jacoco, Jqwik and Pitest
+image:img/spock_logo.png[spock logo,100,float="right"]
This blog post covers a common scenario seen in the Groovy community which is
projects which use Java for their production code and Groovy for their tests.
This can be a low risk way for Java shops to try out and become more familiar
@@ -63,7 +64,7 @@ image:img/MathUtilJacocoReport.png[MathUtilSpec coverage
report]
We'll swap to use Spock's data-driven feature and include an additional
testcase:
-[source,groovy]
+[source,groovy,subs="quotes"]
----
def "sum of two biggest numbers"(int a, int b, int c, int d) {
expect:
@@ -72,7 +73,7 @@ def "sum of two biggest numbers"(int a, int b, int c, int d) {
where:
a | b | c | d
2 | 5 | 3 | 8
- 5 | 2 | 3 | 8
+ **5 | 2 | 3 | 8**
}
----
@@ -83,7 +84,7 @@ image:img/MathUtilJacocoReport2.png[MathUtilSpec coverage
report]
That is a little better. We now have 100% line coverage but not 100% branch
coverage.
Let's add one more testcase:
-[source,groovy]
+[source,groovy,subs="quotes"]
----
def "sum of two biggest numbers"(int a, int b, int c, int d) {
expect:
@@ -93,7 +94,7 @@ def "sum of two biggest numbers"(int a, int b, int c, int d) {
a | b | c | d
2 | 5 | 3 | 8
5 | 2 | 3 | 8
- 5 | 4 | 1 | 9
+ **5 | 4 | 1 | 9**
}
----
@@ -104,7 +105,7 @@ image:img/MathUtilJacocoReport3.png[MathUtilSpec coverage
report]
At this point, we might be very confident in our code and ready to ship it to
production.
Before we do, we'll add one more testcase:
-[source,groovy]
+[source,groovy,subs="quotes"]
----
def "sum of two biggest numbers"(int a, int b, int c, int d) {
expect:
@@ -115,7 +116,7 @@ def "sum of two biggest numbers"(int a, int b, int c, int
d) {
2 | 5 | 3 | 8
5 | 2 | 3 | 8
5 | 4 | 1 | 9
- 3 | 2 | 6 | 9
+ **3 | 2 | 6 | 9**
}
----
diff --git a/site/src/site/blog/working-with-sql-databases-with.adoc
b/site/src/site/blog/working-with-sql-databases-with.adoc
index f3a1141..f0f8999 100644
--- a/site/src/site/blog/working-with-sql-databases-with.adoc
+++ b/site/src/site/blog/working-with-sql-databases-with.adoc
@@ -127,41 +127,41 @@ integration with the metadata repository.
When we run the build, it will automatically create
the native app for us:
-[source,shell]
+[subs="quotes,macros"]
----
-paulk@pop-os:/extra/projects/groovy-graalvm-h2$ ./gradlew clean nativeRun
+[lime]#paulk@pop-os#:[blue]##/extra/projects/groovy-graalvm-h2##$ ./gradlew
clean nativeRun
...
> Task :nativeCompile
[native-image-plugin] Using executable path:
/extra/devtools/graalvm-ce-java17-22.2.0/bin/native-image
-====================================================================================================
+==========================================================================================
GraalVM Native Image: Generating 'H2Demo' (executable)...
-====================================================================================================
+==========================================================================================
...
-[1/7] Initializing...
(5.3s @ 0.26GB)
+[blue]##[1/7] Initializing...##
(5.3s @ 0.26GB)
Version info: 'GraalVM 22.2.0 Java 17 CE'
Java version info: '17.0.4+8-jvmci-22.2-b06'
C compiler: gcc (linux, x86_64, 11.2.0)
Garbage collector: Serial GC
1 user-specific feature(s)
- com.oracle.svm.polyglot.groovy.GroovyIndyInterfaceFeature
-[2/7] Performing analysis... [************]
(51.7s @ 1.82GB)
+[blue]##[2/7] Performing analysis...## [pass:v[************]]
(51.7s @ 1.82GB)
10,597 (90.60%) of 11,697 classes reachable
17,002 (64.13%) of 26,510 fields reachable
58,165 (63.45%) of 91,666 methods reachable
393 classes, 100 fields, and 2,057 methods registered for reflection
65 classes, 74 fields, and 55 methods registered for JNI access
4 native libraries: dl, pthread, rt, z
-[3/7] Building universe...
(8.0s @ 4.02GB)
-[4/7] Parsing methods... [**]
(4.8s @ 3.85GB)
-[5/7] Inlining methods... [***]
(3.0s @ 1.72GB)
-[6/7] Compiling methods... [******]
(38.0s @ 3.63GB)
-[7/7] Creating image...
(5.9s @ 1.70GB)
+[blue]#[3/7] Building universe...#
(8.0s @ 4.02GB)
+[blue]#[4/7] Parsing methods...# [pass:v[**]]
(4.8s @ 3.85GB)
+[blue]##[5/7] Inlining methods...## [pass:v[***]]
(3.0s @ 1.72GB)
+[blue]##[6/7] Compiling methods...## [pass:v[******]]
(38.0s @ 3.63GB)
+[blue]##[7/7] Creating image...##
(5.9s @ 1.70GB)
26.65MB (46.64%) for code area: 38,890 compilation units
28.04MB (49.05%) for image heap: 359,812 objects and 66 resources
2.46MB ( 4.31%) for other data
57.15MB in total
-----------------------------------------------------------------------------------------------------
-Top 10 packages in code area: Top 10 object
types in image heap:
+------------------------------------------------------------------------------------------
+[gold]#Top 10 packages in code area: Top 10
object types in image heap:#
1.48MB sun.security.ssl 5.85MB byte[]
for code metadata
1.06MB java.util 2.82MB
java.lang.String
979.43KB java.lang.invoke 2.78MB
java.lang.Class
@@ -173,34 +173,34 @@ Top 10 packages in code area:
Top 10 object types
476.03KB c.s.org.apache.xerces.internal.impl.xs.traversers 715.65KB byte[]
for embedded resources
468.69KB java.lang 584.75KB
java.util.HashMap$Node[]
18.87MB for 370 more packages 8.28MB for 2535
more object types
-----------------------------------------------------------------------------------------------------
+------------------------------------------------------------------------------------------
3.9s (3.2% of total time) in 30 GCs | Peak RSS: 6.22GB
| CPU load: 6.48
-----------------------------------------------------------------------------------------------------
-Produced artifacts:
+------------------------------------------------------------------------------------------
+[gold]#Produced artifacts:#
/extra/projects/groovy-graalvm-h2/build/native/nativeCompile/H2Demo
(executable)
/extra/projects/groovy-graalvm-h2/build/native/nativeCompile/H2Demo.build_artifacts.txt
(txt)
-=====================================================================================================
+===========================================================================================
Finished generating 'H2Demo' in 2m 1s.
[native-image-plugin] Native Image written to:
/extra/projects/groovy-graalvm-h2/build/native/nativeCompile
> Task :nativeRun
-[ID:1, NAME:Lord Archimonde]
+[aqua]##[ID:1, NAME:Lord Archimonde]
[ID:2, NAME:Arthur]
[ID:3, NAME:Gilbert]
-[ID:4, NAME:Grug]
+[ID:4, NAME:Grug]##
----
== Checking the native image speed
We can also check the speed once the native image is built:
-[source,shell]
+[subs="quotes"]
----
-paulk@pop-os:/extra/projects/groovy-graalvm-h2$ time
build/native/nativeCompile/H2Demo
-[ID:1, NAME:Lord Archimonde]
+[lime]#paulk@pop-os#:[blue]##/extra/projects/groovy-graalvm-h2##$ time
build/native/nativeCompile/H2Demo
+[aqua]##[ID:1, NAME:Lord Archimonde]
[ID:2, NAME:Arthur]
[ID:3, NAME:Gilbert]
-[ID:4, NAME:Grug]
+[ID:4, NAME:Grug]##
real 0m0.027s
user 0m0.010s