From 421a7ab0e6a30e3b48283d6ac49fcec59415a7e9 Mon Sep 17 00:00:00 2001 From: Susan Cheng Date: Sat, 15 Apr 2023 13:01:51 +0800 Subject: [PATCH] Update ImageCodecTest.swift --- Tests/DoggieTests/ImageCodecTest.swift | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Tests/DoggieTests/ImageCodecTest.swift b/Tests/DoggieTests/ImageCodecTest.swift index 8382ea89..c3647917 100644 --- a/Tests/DoggieTests/ImageCodecTest.swift +++ b/Tests/DoggieTests/ImageCodecTest.swift @@ -189,9 +189,13 @@ class ImageCodecTest: XCTestCase { for (i, pixel) in zip(answer, pixels) { - let red = round(Double(((i >> 10) & 0x1F) * 0xFF) / 31) / 255 - let green = round(Double(((i >> 5) & 0x1F) * 0xFF) / 31) / 255 - let blue = round(Double((i & 0x1F) * 0xFF) / 31) / 255 + let r = ((i >> 10) & 0x1F) * 0xFF + let g = ((i >> 5) & 0x1F) * 0xFF + let b = (i & 0x1F) * 0xFF + + let red = round(Double(r) / 31) / 255 + let green = round(Double(g) / 31) / 255 + let blue = round(Double(b) / 31) / 255 XCTAssertEqual(red, pixel.red) XCTAssertEqual(green, pixel.green) @@ -229,9 +233,13 @@ class ImageCodecTest: XCTestCase { for (i, pixel) in zip(answer, pixels) { - let red = round(Double(((i >> 10) & 0x1F) * 0xFF) / 31) / 255 - let green = round(Double(((i >> 5) & 0x1F) * 0xFF) / 31) / 255 - let blue = round(Double((i & 0x1F) * 0xFF) / 31) / 255 + let r = ((i >> 10) & 0x1F) * 0xFF + let g = ((i >> 5) & 0x1F) * 0xFF + let b = (i & 0x1F) * 0xFF + + let red = round(Double(r) / 31) / 255 + let green = round(Double(g) / 31) / 255 + let blue = round(Double(b) / 31) / 255 XCTAssertEqual(red, pixel.red) XCTAssertEqual(green, pixel.green) @@ -269,9 +277,13 @@ class ImageCodecTest: XCTestCase { for (i, pixel) in zip(answer, pixels) { - let red = round(Double(((i >> 24) & 0xFF) * 0xFFFF) / 255) / 65535 - let green = round(Double(((i >> 16) & 0xFF) * 0xFFFF) / 255) / 65535 - let blue = Double(i & 0xFFFF) / 65535 + let r = ((i >> 24) & 0xFF) * 0xFFFF + let g = ((i >> 16) & 0xFF) * 0xFFFF + let b = i & 0xFFFF + + let red = round(Double(r) / 255) / 65535 + let green = round(Double(g) / 255) / 65535 + let blue = Double(b) / 65535 XCTAssertEqual(red, pixel.red) XCTAssertEqual(green, pixel.green)