Skip to content

Commit

Permalink
Rearranged files to target JVM, implement tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnieves81 committed May 10, 2024
1 parent 7477425 commit 0730073
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 37 deletions.
8 changes: 4 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ trait MorphirModule extends Cross.Module[String] with CrossPlatform {
object sdk extends Module {
object core extends CrossPlatform with CrossValue {
trait Shared extends MorphirCommonCrossModule with MorphirPublishModule {
def ivyDeps = Agg(
Deps.org.`scala-lang`.modules.`scala-collection-compat`,
Deps.com.`47Deg`.memeid4s
)
def ivyDeps = Agg(Deps.org.`scala-lang`.modules.`scala-collection-compat`)
}
object jvm extends Shared with MorphirJVMModule {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.com.`47Deg`.memeid4s
)
object test extends ScalaTests with CommonZioTestModule
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package morphir.sdk
import memeid4s.UUID as MUUID

import scala.util.Try
import memeid4s.{ UUID => MUUID }

object UUID {
val Nil: UUID = memeid4s.UUID.Nil
type UUID = MUUID

val Nil: UUID = MUUID.Nil

type V1 = MUUID.V1

Expand All @@ -29,10 +30,6 @@ object UUID {
def random: UUID = MUUID.V4.random
}

def unapply(str: String): Option[UUID] =
if (str.nonEmpty) UUID.from(str).toOption
else None

/** Creates a valid [[UUID]] from two [[_root_.scala.Long Long]] values representing the most/least significant bits.
*
* @param msb
Expand Down
1 change: 0 additions & 1 deletion morphir/sdk/core/src/morphir/sdk/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ package morphir
package object sdk {
val StringModule: StringModule = String
type StringModule = String.type
type UUID = memeid4s.UUID
}
82 changes: 82 additions & 0 deletions morphir/sdk/core/test/jvm/src/UUIDSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import morphir.testing.MorphirBaseSpec
import zio.test.*
import zio.test.Assertion.*
import memeid4s.{ UUID => MUUID }

object UUIDSpec extends MorphirBaseSpec {
def spec = suite("UUID Tests")(
test("Generate UUID from valid String") {
val uuid = UUID.V4.random
assert(UUID.from(uuid.toString))(isRight(equalTo(uuid)))
},
test("Return Throwable from invalid String") {
assert(UUID.from("0f769c4185a634208b09bb63bce12014"))(isLeft)
},
test("UUID from msb and lsb") {
check(Gen.long) { (msb) =>
assertEquals(UUID.from(msb, 0xc000000000000000L), MUUID.from(msb, 0xc000000000000000L))
}
},
suite("V1 UUID")(
test("Generate unique V1 UUIDs") {
assert((1 to 999).map(_ => UUID.V1.next()).toSet.size)(equalTo(999))
}
),
suite("V3 UUID")(
test("Generate same V3 UUID for same namespace and name") {
val namespace = UUID.V4.random
val name = "Test Name!"
val u1 = UUID.V3(namespace, name)
val u2 = UUID.V3(namespace, name)
assertEquals(u1, u2)
},
test("Generate unique V3 UUID for unique namespace") {
val namespace1 = UUID.V4.random
val namespace2 = UUID.V4.random
val name = "Test Name!"
val u1 = UUID.V3(namespace1, name)
val u2 = UUID.V3(namespace2, name)
assertTrue(u1 != u2)
},
test("Generate unique V3 UUID for unique names") {
val namespace = UUID.V4.random
val name1 = "Test Name!"
val name2 = "Test Name 2!"
val u1 = UUID.V3(namespace, name1)
val u2 = UUID.V3(namespace, name2)
assertTrue(u1 != u2)
}
),
suite("V4 UUID")(
test("Generate Uniquely Random V4 UUIDs") {
assert((1 to 999).map(_ => UUID.V4.random).toSet.size)(equalTo(999))
}
),
suite("V5 UUID")(
test("Generate same V5 UUID for same namespace and name") {
val namespace = UUID.V4.random
val name = "Test Name!"
val u1 = UUID.V5(namespace, name)
val u2 = UUID.V5(namespace, name)
assertEquals(u1, u2)
},
test("Generate unique V5 UUID for unique namespace") {
val namespace1 = UUID.V4.random
val namespace2 = UUID.V4.random
val name = "Test Name!"
val u1 = UUID.V5(namespace1, name)
val u2 = UUID.V5(namespace2, name)
assertTrue(u1 != u2)
},
test("Generate unique V5 UUID for unique names") {
val namespace = UUID.V4.random
val name1 = "Test Name!"
val name2 = "Test Name 2!"
val u1 = UUID.V5(namespace, name1)
val u2 = UUID.V5(namespace, name2)
assertTrue(u1 != u2)
}
)
)

}
25 changes: 0 additions & 25 deletions morphir/sdk/core/test/src/morphir/sdk/UUIDSpec.scala

This file was deleted.

0 comments on commit 0730073

Please sign in to comment.