@@ -128,6 +128,70 @@ class TCompactProtocolTests: XCTestCase {
128128 }
129129 }
130130
131+ func testInt32ZigZag( ) {
132+ let zero : Int32 = 0
133+ let one : Int32 = 1
134+ let nOne : Int32 = - 1
135+ let two : Int32 = 2
136+ let nTwo : Int32 = - 2
137+ let max = Int32 . max
138+ let min = Int32 . min
139+
140+ XCTAssertEqual ( proto. i32ToZigZag ( zero) , UInt32 ( 0 ) , " Error 32bit zigzag on \( zero) " )
141+ XCTAssertEqual ( proto. zigZagToi32 ( 0 ) , zero, " Error 32bit zigzag on \( zero) " )
142+
143+ XCTAssertEqual ( proto. i32ToZigZag ( nOne) , UInt32 ( 1 ) , " Error 32bit zigzag on \( nOne) " )
144+ XCTAssertEqual ( proto. zigZagToi32 ( 1 ) , nOne, " Error 32bit zigzag on \( nOne) " )
145+
146+ XCTAssertEqual ( proto. i32ToZigZag ( one) , UInt32 ( 2 ) , " Error 32bit zigzag on \( one) " )
147+ XCTAssertEqual ( proto. zigZagToi32 ( 2 ) , one, " Error 32bit zigzag on \( one) " )
148+
149+ XCTAssertEqual ( proto. i32ToZigZag ( nTwo) , UInt32 ( 3 ) , " Error 32bit zigzag on \( nTwo) " )
150+ XCTAssertEqual ( proto. zigZagToi32 ( 3 ) , nTwo, " Error 32bit zigzag on \( nTwo) " )
151+
152+ XCTAssertEqual ( proto. i32ToZigZag ( two) , UInt32 ( 4 ) , " Error 32bit zigzag on \( two) " )
153+ XCTAssertEqual ( proto. zigZagToi32 ( 4 ) , two, " Error 32bit zigzag on \( two) " )
154+
155+ let uMaxMinusOne : UInt32 = UInt32 . max - 1
156+ XCTAssertEqual ( proto. i32ToZigZag ( max) , uMaxMinusOne, " Error 32bit zigzag on \( max) " )
157+ XCTAssertEqual ( proto. zigZagToi32 ( uMaxMinusOne) , max, " Error 32bit zigzag on \( max) " )
158+
159+ XCTAssertEqual ( proto. i32ToZigZag ( min) , UInt32 . max, " Error 32bit zigzag on \( min) " )
160+ XCTAssertEqual ( proto. zigZagToi32 ( UInt32 . max) , min, " Error 32bit zigzag on \( min) " )
161+ }
162+
163+ func testInt64ZigZag( ) {
164+ let zero : Int64 = 0
165+ let one : Int64 = 1
166+ let nOne : Int64 = - 1
167+ let two : Int64 = 2
168+ let nTwo : Int64 = - 2
169+ let max = Int64 . max
170+ let min = Int64 . min
171+
172+ XCTAssertEqual ( proto. i64ToZigZag ( zero) , UInt64 ( 0 ) , " Error 64bit zigzag on \( zero) " )
173+ XCTAssertEqual ( proto. zigZagToi64 ( 0 ) , zero, " Error 64bit zigzag on \( zero) " )
174+
175+ XCTAssertEqual ( proto. i64ToZigZag ( nOne) , UInt64 ( 1 ) , " Error 64bit zigzag on \( nOne) " )
176+ XCTAssertEqual ( proto. zigZagToi64 ( 1 ) , nOne, " Error 64bit zigzag on \( nOne) " )
177+
178+ XCTAssertEqual ( proto. i64ToZigZag ( one) , UInt64 ( 2 ) , " Error 64bit zigzag on \( one) " )
179+ XCTAssertEqual ( proto. zigZagToi64 ( 2 ) , one, " Error 64bit zigzag on \( one) " )
180+
181+ XCTAssertEqual ( proto. i64ToZigZag ( nTwo) , UInt64 ( 3 ) , " Error 64bit zigzag on \( nTwo) " )
182+ XCTAssertEqual ( proto. zigZagToi64 ( 3 ) , nTwo, " Error 64bit zigzag on \( nTwo) " )
183+
184+ XCTAssertEqual ( proto. i64ToZigZag ( two) , UInt64 ( 4 ) , " Error 64bit zigzag on \( two) " )
185+ XCTAssertEqual ( proto. zigZagToi64 ( 4 ) , two, " Error 64bit zigzag on \( two) " )
186+
187+ let uMaxMinusOne : UInt64 = UInt64 . max - 1
188+ XCTAssertEqual ( proto. i64ToZigZag ( max) , uMaxMinusOne, " Error 64bit zigzag on \( max) " )
189+ XCTAssertEqual ( proto. zigZagToi64 ( uMaxMinusOne) , max, " Error 64bit zigzag on \( max) " )
190+
191+ XCTAssertEqual ( proto. i64ToZigZag ( min) , UInt64 . max, " Error 64bit zigzag on \( min) " )
192+ XCTAssertEqual ( proto. zigZagToi64 ( UInt64 . max) , min, " Error 64bit zigzag on \( min) " )
193+ }
194+
131195 static var allTests : [ ( String , ( TCompactProtocolTests ) -> ( ) throws -> Void ) ] {
132196 return [
133197 ( " testInt8WriteRead " , testInt8WriteRead) ,
@@ -138,7 +202,9 @@ class TCompactProtocolTests: XCTestCase {
138202 ( " testBoolWriteRead " , testBoolWriteRead) ,
139203 ( " testStringWriteRead " , testStringWriteRead) ,
140204 ( " testDataWriteRead " , testDataWriteRead) ,
141- ( " testStructWriteRead " , testStructWriteRead)
205+ ( " testStructWriteRead " , testStructWriteRead) ,
206+ ( " testInt32ZigZag " , testInt32ZigZag) ,
207+ ( " testInt64ZigZag " , testInt64ZigZag)
142208 ]
143209 }
144210}
0 commit comments