-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests for AssignabilityDeterminerSpec
- Loading branch information
Marcel Philipiak
committed
Nov 25, 2024
1 parent
6716c23
commit 6f7187c
Showing
2 changed files
with
67 additions
and
13 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...api/src/test/scala/pl/touk/nussknacker/engine/api/typed/AssignabilityDeterminerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package pl.touk.nussknacker.engine.api.typed | ||
|
||
import cats.data.NonEmptyList | ||
import cats.data.Validated.{Invalid, Valid} | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.prop.TableDrivenPropertyChecks.forAll | ||
import org.scalatest.prop.Tables.Table | ||
import pl.touk.nussknacker.engine.api.typed._ | ||
|
||
class AssignabilityDeterminerSpec extends AnyFunSuite with Matchers { | ||
|
||
// Test data table: (sourceType, targetType, expectedStrict, expectedLoose) | ||
val strictConversionCases = Table( | ||
("sourceType", "targetType", "expectedStrict", "expectedLoose"), | ||
(typing.Typed[Int], typing.Typed[Int], Valid(()), Valid(())), // Same primitive type | ||
(typing.Typed[Int], typing.Typed[Double], Valid(()), Valid(())), // Primitive widening | ||
(typing.Typed[List[Int]], typing.Typed[List[Int]], Valid(()), Valid(())), // Same generic type | ||
(typing.Typed[List[Int]], typing.Typed[List[Any]], Valid(()), Valid(())), // Generic type variance | ||
(typing.Typed[Map[String, Int]], typing.Typed[Map[String, Int]], Valid(()), Valid(())), // Same map type | ||
(typing.Typed[Map[String, Int]], typing.Typed[Map[Any, Any]], Valid(()), Valid(())) | ||
) // Different records | ||
|
||
test("isAssignableStrict should pass for strict cases") { | ||
forAll(strictConversionCases) { (sourceType, targetType, expectedStrict, _) => | ||
val result = AssignabilityDeterminer.isAssignableStrict(sourceType, targetType) | ||
result shouldBe expectedStrict | ||
} | ||
} | ||
|
||
test("isAssignableLoose should pass for strict cases") { | ||
forAll(strictConversionCases) { (sourceType, targetType, _, expectedLoose) => | ||
val result = AssignabilityDeterminer.isAssignableLoose(sourceType, targetType) | ||
result shouldBe expectedLoose | ||
} | ||
} | ||
|
||
val looseConversionCases = Table( | ||
("sourceType", "targetType", "expectedStrict", "expectedLoose"), | ||
(typing.Typed[Long], typing.Typed[Int], Invalid(NonEmptyList.of("")), Valid(())), | ||
(typing.Typed[Double], typing.Typed[Int], Invalid(NonEmptyList.of("")), Invalid(NonEmptyList.of(""))), | ||
(typing.Typed[BigDecimal], typing.Typed[Int], Invalid(NonEmptyList.of("")), Invalid(NonEmptyList.of(""))) | ||
) | ||
|
||
test("isAssignableStrict should fail for looser numerical cases") { | ||
forAll(looseConversionCases) { (sourceType, targetType, expectedStrict, _) => | ||
val result = AssignabilityDeterminer.isAssignableStrict(sourceType, targetType) | ||
result match { | ||
case Valid(_) if expectedStrict.isValid => succeed | ||
case Invalid(_) if expectedStrict.isInvalid => succeed | ||
case _ => fail(s"Unexpected result: $result for types $sourceType -> $targetType") | ||
} | ||
} | ||
} | ||
|
||
test("isAssignableLoose should pass for looser cases") { | ||
forAll(looseConversionCases) { (sourceType, targetType, _, expectedLoose) => | ||
val result = AssignabilityDeterminer.isAssignableLoose(sourceType, targetType) | ||
result match { | ||
case Valid(_) if expectedLoose.isValid => succeed | ||
case Invalid(_) if expectedLoose.isInvalid => succeed | ||
case _ => fail(s"Unexpected result: $result for types $sourceType -> $targetType") | ||
} | ||
} | ||
} | ||
|
||
} |
13 changes: 0 additions & 13 deletions
13
...ents-api/src/test/scala/pl/touk/nussknacker/engine/api/typed/SubclassDeterminerSpec.scala
This file was deleted.
Oops, something went wrong.