diff --git a/tests/gray-scale.toit b/tests/gray-scale.toit deleted file mode 100644 index 7da7c08..0000000 --- a/tests/gray-scale.toit +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2021 Toitware ApS. -// Use of this source code is governed by a Zero-Clause BSD license that can -// be found in the TESTS_LICENSE file. - -import expect show * -import font show Font -import pixel-display show * -import pixel-display.gray-scale show * - -class TestDriver extends AbstractDriver: - buffer := ByteArray 64 * 128 - - width ::= 128 - height ::= 64 - flags ::= FLAG-GRAY-SCALE | FLAG-PARTIAL-UPDATES - draw-gray-scale left/int top/int right/int bottom/int pixels/ByteArray -> none: - w := right - left - (bottom - top).repeat: | iy | - w.repeat: | ix | - buffer[left + ix + (top + iy) * width] = pixels[ix + iy * w] - - pixel-at x y: - return buffer[x + y * width] - -main: - driver := TestDriver - display := PixelDisplay.gray-scale driver - display.background = 1 - - sans10 := Font.get "sans10" - - ctx := display.context --landscape --color=250 --font=sans10 - - display.filled-rectangle ctx 10 20 30 40 - display.text ctx 50 20 "Testing" - display.text ctx 50 40 "the display" - display.draw - display.text ctx 50 60 "for the win" - - display.draw - - for y := 0; y < driver.height; y += 2: - line := "" - driver.width.repeat: | x | - top-half := (driver.pixel-at x y) < 128 - bottom-half := (driver.pixel-at x y + 1) < 128 - line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" - print line - - 50.repeat: | x | - driver.height.repeat: | y | - if x < 10 or y < 20 or x >= 40 or y >= 60: - expect-equals 1 (driver.pixel-at x y) - else: - expect-equals 250 (driver.pixel-at x y) diff --git a/tests/several-color.toit b/tests/several-color.toit deleted file mode 100644 index 23cd432..0000000 --- a/tests/several-color.toit +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2021 Toitware ApS. -// Use of this source code is governed by a Zero-Clause BSD license that can -// be found in the TESTS_LICENSE file. - -import expect show * -import font show Font -import pixel-display show * -import pixel-display.several-color show * - -class TestDriver extends AbstractDriver: - buffer := ByteArray 64 * 128 - - width ::= 128 - height ::= 64 - flags ::= FLAG-SEVERAL-COLOR | FLAG-PARTIAL-UPDATES - draw-several-color left/int top/int right/int bottom/int pixels/ByteArray -> none: - w := right - left - (bottom - top).repeat: | iy | - w.repeat: | ix | - buffer[left + ix + (top + iy) * width] = pixels[ix + iy * w] - - pixel-at x y: - return buffer[x + y * width] - -main: - driver := TestDriver - display := PixelDisplay.several-color driver - display.background = 1 - - sans10 := Font.get "sans10" - - ctx := display.context --landscape --color=250 --font=sans10 - - display.filled-rectangle ctx 10 20 30 40 - display.text ctx 50 20 "Testing" - display.text ctx 50 40 "the display" - display.draw - display.text ctx 50 60 "for the win" - - display.draw - - for y := 0; y < driver.height; y += 2: - line := "" - driver.width.repeat: | x | - top-half := (driver.pixel-at x y) < 128 - bottom-half := (driver.pixel-at x y + 1) < 128 - line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" - print line - - 50.repeat: | x | - driver.height.repeat: | y | - if x < 10 or y < 20 or x >= 40 or y >= 60: - expect-equals 1 (driver.pixel-at x y) - else: - expect-equals 250 (driver.pixel-at x y) diff --git a/tests/simple.toit b/tests/simple.toit deleted file mode 100644 index 74ea021..0000000 --- a/tests/simple.toit +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright (C) 2021 Toitware ApS. -// Use of this source code is governed by a Zero-Clause BSD license that can -// be found in the TESTS_LICENSE file. - -import expect show * -import font show Font -import pixel-display show * -import pixel-display.two-color -import pixel-display.true-color - -class TwoColorDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-2-COLOR - draw-two-color left/int top/int right/int bottom/int pixels/ByteArray -> none: - -class ThreeColorDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-3-COLOR - draw-two-bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: - -class FourGrayDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-4-COLOR - draw-two-bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: - -class TrueColorDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-TRUE-COLOR - draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: - -class GrayScaleDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-GRAY-SCALE - draw-gray-scale left/int top/int right/int bottom/int pixels/ByteArray -> none: - -class SeveralColorDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-SEVERAL-COLOR - draw-several-color left/int top/int right/int bottom/int pixels/ByteArray -> none: - -class DrawRecordingDriver extends AbstractDriver: - width ::= 128 - height ::= 64 - flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES - r-left := 0 - r-top := 0 - r-right := 0 - r-bottom := 0 - - constructor: - reset - - reset -> none: - r-left = 1_000_000 - r-top = 1_000_000 - r-right = -1 - r-bottom = -1 - - draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: - r-left = min r-left left - r-top = min r-top top - r-right = max r-right right - r-bottom = max r-bottom bottom - -main: - for-the-win-test - invalidate-test - -invalidate-test: - driver := DrawRecordingDriver - display := PixelDisplay.true-color driver - - context := display.context - - display.draw - driver.reset - - print "Rectangle" - display.filled-rectangle context 42 23 12 10 - display.draw - - expect-equals driver.r-left 40 // 42 rounded down. - expect-equals driver.r-right 56 // 42 + 12 rounded up. - expect-equals driver.r-top 16 // 23 rounded down. - expect-equals driver.r-bottom 40 // 23 + 10 rounded up. - - driver.reset - - print "Window" - - window := true-color.SimpleWindow 42 23 22 20 context.transform - 0 // Border width. - 0 // Border color. - 0 // Background color. - - display.add window - - display.draw - - expect-equals driver.r-left 40 // 42 rounded down. - expect-equals driver.r-right 64 // 42 + 22 rounded up. - expect-equals driver.r-top 16 // 23 rounded down. - expect-equals driver.r-bottom 48 // 23 + 20 rounded up. - - driver.reset - - // Place rectangle at window-relative coordinates. - rect-in-window := true-color.FilledRectangle - 0 // Color. - 8 // x. - 0 // y. - 10 // w. - 1 // h. - window.transform - - window.add rect-in-window - - display.draw - - expect-equals driver.r-left 48 // 42 + 8 rounded down. - expect-equals driver.r-right 64 // 42 + 8 + 10 rounded up. - expect-equals driver.r-top 16 // 23 + 0 rounded down. - expect-equals driver.r-bottom 24 // 23 + 0 + 1 rounded up. - -for-the-win-test: - driver2 := TwoColorDriver - display2 := PixelDisplay.two-color driver2 - - driver3 := ThreeColorDriver - display3 := PixelDisplay.three-color driver3 - - driver4 := FourGrayDriver - display4 := PixelDisplay.four-gray driver4 - - driver-true := TrueColorDriver - display-true := PixelDisplay.true-color driver-true - - driver-gray := GrayScaleDriver - display-gray := PixelDisplay.gray-scale driver-gray - - driver-several := SeveralColorDriver - display-several := PixelDisplay.several-color driver-several - - sans10 := Font.get "sans10" - - [display2, display3, display4, display-true, display-gray, display-several].do: | display | - ctx := display.context --landscape --font=sans10 - display.filled-rectangle ctx 10 20 30 40 - display.text ctx 50 20 "Testing" - display.text ctx 50 40 "the display" - display.text ctx 50 60 "for the win" - display.draw diff --git a/tests/true-color.toit b/tests/true-color.toit deleted file mode 100644 index abd9dab..0000000 --- a/tests/true-color.toit +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2021 Toitware ApS. -// Use of this source code is governed by a Zero-Clause BSD license that can -// be found in the TESTS_LICENSE file. - -import expect show * -import font show Font -import pixel-display show * -import pixel-display.true-color show * - -class TestDriver extends AbstractDriver: - buffer := ByteArray 3 * 64 * 128 - - width ::= 128 - height ::= 64 - flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES - draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: - w := right - left - (bottom - top).repeat: | iy | - w.repeat: | ix | - buffer[0 + 3 * (left + ix + (top + iy) * width)] = r[ix + iy * w] - buffer[1 + 3 * (left + ix + (top + iy) * width)] = g[ix + iy * w] - buffer[2 + 3 * (left + ix + (top + iy) * width)] = b[ix + iy * w] - - red-at x y: - return buffer[0 + 3 * (x + y * width)] - - green-at x y: - return buffer[1 + 3 * (x + y * width)] - - blue-at x y: - return buffer[2 + 3 * (x + y * width)] - -main: - driver := TestDriver - display := PixelDisplay.true-color driver - display.background = get-rgb 0 1 2 - - sans10 := Font.get "sans10" - - ctx := display.context --landscape --color=(get-rgb 255 120 0) --font=sans10 - - display.filled-rectangle ctx 10 20 30 40 - display.text ctx 50 20 "Testing" - display.text ctx 50 40 "the display" - display.draw - display.text ctx 50 60 "for the win" - - display.draw - - for y := 0; y < driver.height; y += 2: - line := "" - driver.width.repeat: | x | - top-half := (driver.red-at x y) < 128 - bottom-half := (driver.red-at x y + 1) < 128 - line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" - print line - - 50.repeat: | x | - driver.height.repeat: | y | - if x < 10 or y < 20 or x >= 40 or y >= 60: - expect-equals 0 (driver.red-at x y) - expect-equals 1 (driver.green-at x y) - expect-equals 2 (driver.blue-at x y) - else: - expect-equals 255 (driver.red-at x y) - expect-equals 120 (driver.green-at x y) - expect-equals 0 (driver.blue-at x y)