| 1 | import XCTest |
| 2 | @testable import LChatCore |
| 3 | |
| 4 | // 🤖 Pins the notification monogram to the Avatar view's rules (initial + |
| 5 | // djb2 palette pick) so a person's banner face can't drift from their in-app |
| 6 | // face, and smoke-tests the render. |
| 7 | final class MonogramImageTests: XCTestCase { |
| 8 | func testInitialMirrorsAvatarView() { |
| 9 | XCTAssertEqual(MonogramImage.initial(for: "paul"), "P") |
| 10 | XCTAssertEqual(MonogramImage.initial(for: " Éowyn "), "É") |
| 11 | XCTAssertEqual(MonogramImage.initial(for: " "), "?") |
| 12 | XCTAssertEqual(MonogramImage.initial(for: "🦊 Fox"), "🦊") |
| 13 | } |
| 14 | |
| 15 | func testPaletteIndexIsDeterministicDjb2() { |
| 16 | // djb2("Eleven") computed by the Avatar view's exact loop. |
| 17 | var h = 5381 |
| 18 | for b in "Eleven".utf8 { h = (h &* 33) &+ Int(b) } |
| 19 | XCTAssertEqual(MonogramImage.paletteIndex(for: "Eleven"), abs(h) % 8) |
| 20 | XCTAssertEqual(MonogramImage.paletteIndex(for: "Eleven"), |
| 21 | MonogramImage.paletteIndex(for: "Eleven")) |
| 22 | XCTAssertTrue((0..<8).contains(MonogramImage.paletteIndex(for: "任意の名前"))) |
| 23 | } |
| 24 | |
| 25 | func testRendersNonEmptyPNG() throws { |
| 26 | let data = try XCTUnwrap(MonogramImage.pngData(name: "Paul")) |
| 27 | // PNG magic — a real encode, not junk bytes. |
| 28 | XCTAssertEqual(Array(data.prefix(4)), [0x89, 0x50, 0x4E, 0x47]) |
| 29 | XCTAssertGreaterThan(data.count, 500) |
| 30 | } |
| 31 | } |
| 32 | |