Skip to content

Commit

Permalink
Merge pull request #15 from LibreCybernetics/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
fabianhjr authored Sep 23, 2023
2 parents 4573628 + d9f827b commit 0504feb
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 49 deletions.
54 changes: 19 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,28 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [3.3.1]
java: [temurin@11, temurin@17, temurin@20]
java: [zulu@17, zulu@21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
- name: Setup Java (zulu@17)
if: matrix.java == 'zulu@17'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: sbt

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: temurin
distribution: zulu
java-version: 17
cache: sbt

- name: Setup Java (temurin@20)
if: matrix.java == 'temurin@20'
- name: Setup Java (zulu@21)
if: matrix.java == 'zulu@21'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 20
distribution: zulu
java-version: 21
cache: sbt

- name: Check that workflows are up to date
Expand All @@ -63,7 +55,7 @@ jobs:
run: sbt '++ ${{ matrix.scala }}' test

- name: Compress target directories
run: tar cf targets.tar target scalacheck/.native/target .js/target core/.native/target core/.js/target core/.jvm/target .jvm/target .native/target scalacheck/.jvm/target scalacheck/.js/target project/target
run: tar cf targets.tar target scalacheck/.native/target .js/target core/.native/target core/.js/target core/.jvm/target .jvm/target .native/target scalatest/.native/target scalacheck/.jvm/target scalatest/.js/target scalatest/.jvm/target scalacheck/.js/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v3
Expand All @@ -79,36 +71,28 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [3.3.1]
java: [temurin@11]
java: [zulu@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
cache: sbt

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
- name: Setup Java (zulu@17)
if: matrix.java == 'zulu@17'
uses: actions/setup-java@v3
with:
distribution: temurin
distribution: zulu
java-version: 17
cache: sbt

- name: Setup Java (temurin@20)
if: matrix.java == 'temurin@20'
- name: Setup Java (zulu@21)
if: matrix.java == 'zulu@21'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 20
distribution: zulu
java-version: 21
cache: sbt

- name: Download target directories (3.3.1)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ CalVer with Patch: `YYYY.MM.MICRO` (Year, Month, Patch)

- CPU: x86_64 (ARM and RISC-V might work but LibreCybernetics currently has no hardware to support development)
- OS: Linux (Neither Windows nor MacOS are supported)
- JDK: OpenJDK actively supported LTS releases and latest version. (Currently: 11, 17, 20)
- Scala: 3.y LTS releases and latest version /w latest scala-native and scala.js (Currently: 3.3.0)
- JDK: Latest 2 supported LTS releases and latest version. (Currently: 17, 21)
- Scala: 3.y LTS releases and latest version /w latest scala-native and scala.js (Currently: 3.3.1)
33 changes: 25 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,30 @@ val scalacheck: CrossProject =
"org.scalacheck" %%% "scalacheck" % Version.scalacheck,
"org.scalatest" %%% "scalatest" % Version.scalatest % Test,
"org.scalatest" %%% "scalatest-wordspec" % Version.scalatest % Test,
"org.scalatestplus" %%% "scalacheck-1-17" % Version.scalatestPlusCheck % Test,
"org.scalatestplus" %%% "scalacheck-1-17" % Version.scalatestPlusCheck % Test
)
)

val scalatest: CrossProject =
crossProject(JVMPlatform, NativePlatform, JSPlatform)
.crossType(CrossType.Pure)
.in(file("scalatest"))
.dependsOn(core)
.settings(sharedSettings)
.settings(
name := "bijection-scalatest",
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % Version.scalatest,
"org.scalatestplus" %%% "scalacheck-1-17" % Version.scalatestPlusCheck,
"org.scalatest" %%% "scalatest-wordspec" % Version.scalatest % Test
)
)

val root: CrossProject =
crossProject(JVMPlatform, NativePlatform, JSPlatform)
.crossType(CrossType.Pure)
.in(file("."))
.aggregate(core, scalacheck)
.aggregate(core, scalacheck, scalatest)
.dependsOn(core)
.enablePlugins(ScalaUnidocPlugin)
.settings(sharedSettings)
Expand All @@ -106,16 +121,18 @@ val root: CrossProject =

val fakeRoot = (project in file("."))
.settings(
publish / skip := true,
sourceDirectory := file("fake")
).aggregate(root.componentProjects.map(projectToRef)*)
publish / skip := true,
sourceDirectory := file("fake")
)
.aggregate(root.componentProjects.map(projectToRef)*)

// CI/CD

import JavaSpec.Distribution

ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("11"),
JavaSpec.temurin("17"),
JavaSpec.temurin("20")
JavaSpec(Distribution.Zulu, "17"),
JavaSpec(Distribution.Zulu, "21")
)

ThisBuild / githubWorkflowTargetTags :=
Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")

// Static Code Analysis

addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.3")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.4")

// Testing

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.5")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.6")

// CI/CD

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.15.0")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.16.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.librecybernetics.data

import scala.util.Try

import org.scalacheck.Arbitrary
import org.scalatest
import org.scalatest.{Assertion, Succeeded}
import org.scalatest.matchers.should.Matchers.*
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks.*

extension [A, B](mapBijection: MapBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
whenever(mapBijection.isDefined(a)) {
// Self Inverse
mapBijection(a).flatMap(mapBijection.reverse(_)) should contain(a)
}
}

def checkReverse(using Arbitrary[B]): Assertion =
mapBijection.flip.checkForward

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
yield Succeeded).get
end extension

extension [A, B](pfnBijection: PFnBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
whenever(pfnBijection.isDefined(a)) {
// Self Inverse
pfnBijection(a).flatMap(pfnBijection.reverse(_)) should contain(a)
}
}

def checkReverse(using Arbitrary[B]): Assertion =
pfnBijection.flip.checkForward

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
yield Succeeded).get
end extension

extension [A, B](fnBijection: FnBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
whenever(fnBijection.isDefined(a)) {
// Self Inverse
fnBijection.reverse(fnBijection(a)) shouldBe a
}
}

def checkReverse(using Arbitrary[B]): Assertion =
fnBijection.flip.checkForward

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
yield Succeeded).get
end extension

0 comments on commit 0504feb

Please sign in to comment.