From 59d72720e7b021da0c7e88266c7605e4c9998a39 Mon Sep 17 00:00:00 2001 From: Adam Rocska Date: Wed, 13 May 2020 17:09:11 +0200 Subject: [PATCH] Making code a little bit leaner & added ipv6 tests. Signed-off-by: Adam Rocska --- Sources/Index/InMemoryIndex.swift | 7 +------ Tests/IndexTests/InMemoryIndexTest.swift | 10 ++++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Sources/Index/InMemoryIndex.swift b/Sources/Index/InMemoryIndex.swift index 49ad43b..fe6d64e 100644 --- a/Sources/Index/InMemoryIndex.swift +++ b/Sources/Index/InMemoryIndex.swift @@ -14,11 +14,7 @@ public class InMemoryIndex: Index where Pointer: UnsignedInteger, Point required public convenience init(metadata: Metadata, stream createStream: @autoclosure () -> InputStream) { precondition( metadata.recordSize < (MemoryLayout.size * 8), - """ - The byte size of a record described by the metadata won't fit the memory layout of type \(Pointer.self). - : Metadata Record Size : \(metadata.recordSize) bits - : Memory Layout Size of \(Pointer.self) : \(MemoryLayout.size) bytes.\n - """ + "Can't fit record size of \(metadata.recordSize) bits in \(Pointer.self)'s \(MemoryLayout.size) bytes." ) let stream = createStream() precondition(stream.streamStatus == Stream.Status.notOpen, "should have provided an untouched stream.") @@ -69,7 +65,6 @@ public class InMemoryIndex: Index where Pointer: UnsignedInteger, Point return pointer } } - return nil } diff --git a/Tests/IndexTests/InMemoryIndexTest.swift b/Tests/IndexTests/InMemoryIndexTest.swift index a8c8402..85f4c89 100644 --- a/Tests/IndexTests/InMemoryIndexTest.swift +++ b/Tests/IndexTests/InMemoryIndexTest.swift @@ -25,10 +25,12 @@ class InMemoryIndexTest: XCTestCase { stream: InputStream(fileAtPath: InMemoryIndexTest.countryFilePath)! ) - XCTAssertEqual(628171, index.lookup(.v4("80.99.18.166"))) - XCTAssertEqual(618846, index.lookup(.v4("202.108.22.220"))) - XCTAssertNil(index.lookup(.v4("0.0.0.0"))) - XCTAssertNil(index.lookup(.v4("255.255.255.255"))) + XCTAssertEqual(628171, index.lookup(IpAddress("80.99.18.166"))) + XCTAssertEqual(618846, index.lookup(IpAddress("202.108.22.220"))) + XCTAssertNil(index.lookup(IpAddress("0.0.0.0"))) + XCTAssertNil(index.lookup(IpAddress("255.255.255.255"))) + XCTAssertNil(index.lookup(IpAddress("2001:db8::8a2e:370:7334"))) + XCTAssertEqual(627015, index.lookup(IpAddress("2001:428:4c06:f000::280"))) } }