fix float rounding tests

This commit is contained in:
Irmen de Jong 2021-11-18 22:54:49 +01:00
parent b334d89715
commit 42c8720e8b
2 changed files with 22 additions and 11 deletions

View File

@ -154,7 +154,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
}
@ -166,7 +166,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
}
@ -178,7 +178,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe true
}
@ -190,7 +190,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
}
@ -203,7 +203,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe false
}
@ -216,7 +216,7 @@ class TestMemory: FunSpec({
val assignment = Assignment(target, NumericLiteralValue.optimalInteger(0, Position.DUMMY), Position.DUMMY)
val subroutine = Subroutine("test", mutableListOf(), emptyList(), emptyList(), emptyList(), emptySet(), null, false, false, mutableListOf(decl, assignment), Position.DUMMY)
val module = Module(mutableListOf(subroutine), Position.DUMMY, SourceCode.Generated("test"))
val program = Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
Program("test", DummyFunctions, DummyMemsizer, DummyStringEncoder)
.addModule(module)
target.isIOAddress(C64Target.machine) shouldBe true
}

View File

@ -1,9 +1,12 @@
package prog8tests
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import prog8.ast.base.DataType
import prog8.ast.base.ExpressionError
import prog8.ast.base.Position
import prog8.ast.expressions.ArrayLiteralValue
import prog8.ast.expressions.InferredTypes
@ -31,11 +34,19 @@ class TestNumericLiteralValue: FunSpec({
}
test("test rounding") {
NumericLiteralValue(DataType.BYTE, -2.345, dummyPos).number shouldBe -2.0
NumericLiteralValue(DataType.BYTE, -2.6, dummyPos).number shouldBe -3.0
NumericLiteralValue(DataType.UWORD, 2222.345, dummyPos).number shouldBe 2222.0
NumericLiteralValue(DataType.UWORD, 2222.6, dummyPos).number shouldBe 2223.0
NumericLiteralValue(DataType.FLOAT, 123.456, dummyPos).number shouldBe 123.456
shouldThrow<ExpressionError> {
NumericLiteralValue(DataType.BYTE, -2.345, dummyPos)
}.message shouldContain "refused silent rounding"
shouldThrow<ExpressionError> {
NumericLiteralValue(DataType.BYTE, -2.6, dummyPos)
}.message shouldContain "refused silent rounding"
shouldThrow<ExpressionError> {
NumericLiteralValue(DataType.UWORD, 2222.345, dummyPos)
}.message shouldContain "refused silent rounding"
NumericLiteralValue(DataType.UBYTE, 2.0, dummyPos).number shouldBe 2.0
NumericLiteralValue(DataType.BYTE, -2.0, dummyPos).number shouldBe -2.0
NumericLiteralValue(DataType.UWORD, 2222.0, dummyPos).number shouldBe 2222.0
NumericLiteralValue(DataType.FLOAT, 123.456, dummyPos)
}
test("testEqualsAndNotEquals") {