From aa540da4d9fffe856f629da9bdb0f794ea30033f Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Mon, 14 Nov 2016 22:02:06 +0300 Subject: [PATCH] Added tests for bzip2. --- SWCompression.xcodeproj/project.pbxproj | 24 ++++ Tests/Bzip2Tests.swift | 143 +++++++++++++++++++++--- Tests/Test Files/BZip2/test1.bz2 | Bin 0 -> 58 bytes Tests/Test Files/BZip2/test2.bz2 | Bin 0 -> 802 bytes Tests/Test Files/BZip2/test3.bz2 | Bin 0 -> 835 bytes Tests/Test Files/BZip2/test4.bz2 | Bin 0 -> 66 bytes Tests/Test Files/BZip2/test5.bz2 | Bin 0 -> 14 bytes 7 files changed, 149 insertions(+), 18 deletions(-) create mode 100644 Tests/Test Files/BZip2/test1.bz2 create mode 100644 Tests/Test Files/BZip2/test2.bz2 create mode 100644 Tests/Test Files/BZip2/test3.bz2 create mode 100644 Tests/Test Files/BZip2/test4.bz2 create mode 100644 Tests/Test Files/BZip2/test5.bz2 diff --git a/SWCompression.xcodeproj/project.pbxproj b/SWCompression.xcodeproj/project.pbxproj index 300c5345..49be3ca6 100644 --- a/SWCompression.xcodeproj/project.pbxproj +++ b/SWCompression.xcodeproj/project.pbxproj @@ -58,8 +58,14 @@ 0680E1A11DDA2C3F005C05EB /* test2.gz in Resources */ = {isa = PBXBuildFile; fileRef = 0680E19F1DDA2C3F005C05EB /* test2.gz */; }; 0680E1A41DDA2C5B005C05EB /* test4.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A21DDA2C5B005C05EB /* test4.zlib */; }; 0680E1A51DDA2C5B005C05EB /* test5.zlib in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A31DDA2C5B005C05EB /* test5.zlib */; }; + 0680E1AB1DDA2C90005C05EB /* test1.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A61DDA2C90005C05EB /* test1.bz2 */; }; + 0680E1AC1DDA2C90005C05EB /* test2.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A71DDA2C90005C05EB /* test2.bz2 */; }; + 0680E1AD1DDA2C90005C05EB /* test3.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A81DDA2C90005C05EB /* test3.bz2 */; }; + 0680E1AE1DDA2C90005C05EB /* test4.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1A91DDA2C90005C05EB /* test4.bz2 */; }; + 0680E1AF1DDA2C90005C05EB /* test5.bz2 in Resources */ = {isa = PBXBuildFile; fileRef = 0680E1AA1DDA2C90005C05EB /* test5.bz2 */; }; 0680E1B11DDA2D7C005C05EB /* ZlibTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */; }; 0680E1B31DDA3D0A005C05EB /* GzipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0680E1B21DDA3D0A005C05EB /* GzipTests.swift */; }; + 0680E1B51DDA4076005C05EB /* Bzip2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0680E1B41DDA4075005C05EB /* Bzip2Tests.swift */; }; 06AC9B0D1DC1027900A5066B /* HuffmanLength.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AC9B0C1DC1027900A5066B /* HuffmanLength.swift */; }; 06BE1AD21DB410F100EE0F59 /* SWCompression.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06BE1AC81DB410F100EE0F59 /* SWCompression.framework */; }; 06BE1AD91DB410F100EE0F59 /* SWCompression.h in Headers */ = {isa = PBXBuildFile; fileRef = 06BE1ACB1DB410F100EE0F59 /* SWCompression.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -111,8 +117,14 @@ 0680E19F1DDA2C3F005C05EB /* test2.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = test2.gz; sourceTree = ""; }; 0680E1A21DDA2C5B005C05EB /* test4.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test4.zlib; sourceTree = ""; }; 0680E1A31DDA2C5B005C05EB /* test5.zlib */ = {isa = PBXFileReference; lastKnownFileType = file; path = test5.zlib; sourceTree = ""; }; + 0680E1A61DDA2C90005C05EB /* test1.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test1.bz2; sourceTree = ""; }; + 0680E1A71DDA2C90005C05EB /* test2.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test2.bz2; sourceTree = ""; }; + 0680E1A81DDA2C90005C05EB /* test3.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test3.bz2; sourceTree = ""; }; + 0680E1A91DDA2C90005C05EB /* test4.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test4.bz2; sourceTree = ""; }; + 0680E1AA1DDA2C90005C05EB /* test5.bz2 */ = {isa = PBXFileReference; lastKnownFileType = file; path = test5.bz2; sourceTree = ""; }; 0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZlibTests.swift; sourceTree = ""; }; 0680E1B21DDA3D0A005C05EB /* GzipTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GzipTests.swift; sourceTree = ""; }; + 0680E1B41DDA4075005C05EB /* Bzip2Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bzip2Tests.swift; sourceTree = ""; }; 06AC9B0C1DC1027900A5066B /* HuffmanLength.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HuffmanLength.swift; sourceTree = ""; }; 06BE1AC81DB410F100EE0F59 /* SWCompression.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SWCompression.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 06BE1ACB1DB410F100EE0F59 /* SWCompression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SWCompression.h; sourceTree = ""; }; @@ -190,6 +202,11 @@ 066204721DD9840000353639 /* BZip2 */ = { isa = PBXGroup; children = ( + 0680E1A61DDA2C90005C05EB /* test1.bz2 */, + 0680E1A71DDA2C90005C05EB /* test2.bz2 */, + 0680E1A81DDA2C90005C05EB /* test3.bz2 */, + 0680E1A91DDA2C90005C05EB /* test4.bz2 */, + 0680E1AA1DDA2C90005C05EB /* test5.bz2 */, ); path = BZip2; sourceTree = ""; @@ -266,6 +283,7 @@ 0662046B1DD983FF00353639 /* Test Files */, 0680E1B01DDA2D7C005C05EB /* ZlibTests.swift */, 0680E1B21DDA3D0A005C05EB /* GzipTests.swift */, + 0680E1B41DDA4075005C05EB /* Bzip2Tests.swift */, 061FCE2C1DBCC6A30052F7BE /* Constants.swift */, 0661F06E1DC92391006C3D35 /* PerformanceTests.swift */, 06BE1AD81DB410F100EE0F59 /* Info.plist */, @@ -496,8 +514,10 @@ 066204871DD9840000353639 /* test3.zlib in Resources */, 066204821DD9840000353639 /* test4.gz in Resources */, 066204811DD9840000353639 /* test1.gz in Resources */, + 0680E1AD1DDA2C90005C05EB /* test3.bz2 in Resources */, 0680E1A11DDA2C3F005C05EB /* test2.gz in Resources */, 066204841DD9840000353639 /* performance_test1.gz in Resources */, + 0680E1AB1DDA2C90005C05EB /* test1.bz2 in Resources */, 0662047E1DD9840000353639 /* test3.answer in Resources */, 0680E1A01DDA2C3F005C05EB /* test3.gz in Resources */, 0662047D1DD9840000353639 /* test2.answer in Resources */, @@ -505,10 +525,13 @@ 066204861DD9840000353639 /* test2.zlib in Resources */, 0662047F1DD9840000353639 /* test4.answer in Resources */, 0662047C1DD9840000353639 /* test1.answer in Resources */, + 0680E1AF1DDA2C90005C05EB /* test5.bz2 in Resources */, 066204851DD9840000353639 /* test1.zlib in Resources */, 0680E1A41DDA2C5B005C05EB /* test4.zlib in Resources */, 0680E1A51DDA2C5B005C05EB /* test5.zlib in Resources */, + 0680E1AE1DDA2C90005C05EB /* test4.bz2 in Resources */, 066204801DD9840000353639 /* test5.answer in Resources */, + 0680E1AC1DDA2C90005C05EB /* test2.bz2 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -583,6 +606,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0680E1B51DDA4076005C05EB /* Bzip2Tests.swift in Sources */, 061FCE2D1DBCC6A30052F7BE /* Constants.swift in Sources */, 0680E1B11DDA2D7C005C05EB /* ZlibTests.swift in Sources */, 0680E1B31DDA3D0A005C05EB /* GzipTests.swift in Sources */, diff --git a/Tests/Bzip2Tests.swift b/Tests/Bzip2Tests.swift index 39b2867e..7a5b0f5e 100644 --- a/Tests/Bzip2Tests.swift +++ b/Tests/Bzip2Tests.swift @@ -3,33 +3,140 @@ // SWCompression // // Created by Timofey Solomko on 14.11.16. -// Copyright © 2016 tsolomko. All rights reserved. +// Copyright © 2016 Timofey Solomko. All rights reserved. // import XCTest +@testable import SWCompression class Bzip2Tests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } + static let testType: String = "bz2" - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. + func testBzip2_1() { + let testName = "test1" + guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: Bzip2Tests.testType)) else { + XCTFail("Failed to load test archive") + return } + + guard let decompressedData = try? BZip2.decompress(compressedData: testData) else { + XCTFail("Failed to decompress") + return + } + + guard let decompressedString = String(data: decompressedData, encoding: .utf8) else { + XCTFail("Failed to convert decompressed data to string") + return + } + + guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else { + XCTFail("Failed to get the answer") + return + } + + XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect") + } + + func testBzip2_2() { + let testName = "test1" + guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: Bzip2Tests.testType)) else { + XCTFail("Failed to load test archive") + return + } + + guard let decompressedData = try? BZip2.decompress(compressedData: testData) else { + XCTFail("Failed to decompress") + return + } + + guard let decompressedString = String(data: decompressedData, encoding: .utf8) else { + XCTFail("Failed to convert decompressed data to string") + return + } + + guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else { + XCTFail("Failed to get the answer") + return + } + + XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect") + } + + func testBzip2_3() { + let testName = "test3" + guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: Bzip2Tests.testType)) else { + XCTFail("Failed to load test archive") + return + } + + guard let decompressedData = try? BZip2.decompress(compressedData: testData) else { + XCTFail("Failed to decompress") + return + } + + guard let decompressedString = String(data: decompressedData, encoding: .utf8) else { + XCTFail("Failed to convert decompressed data to string") + return + } + + guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else { + XCTFail("Failed to get the answer") + return + } + + XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect") + } + + func testBzip2_4() { + let testName = "test4" + guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: Bzip2Tests.testType)) else { + XCTFail("Failed to load test archive") + return + } + + guard let decompressedData = try? BZip2.decompress(compressedData: testData) else { + XCTFail("Failed to decompress") + return + } + + guard let decompressedString = String(data: decompressedData, encoding: .utf8) else { + XCTFail("Failed to convert decompressed data to string") + return + } + + guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else { + XCTFail("Failed to get the answer") + return + } + + XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect") + } + + func testBzip2_5() { + let testName = "test5" + guard let testData = try? Data(contentsOf: Constants.url(forTest: testName, withType: Bzip2Tests.testType)) else { + XCTFail("Failed to load test archive") + return + } + + guard let decompressedData = try? BZip2.decompress(compressedData: testData) else { + XCTFail("Failed to decompress") + return + } + + guard let decompressedString = String(data: decompressedData, encoding: .utf8) else { + XCTFail("Failed to convert decompressed data to string") + return + } + + guard let answerString = try? String(contentsOf: Constants.url(forAnswer: testName), encoding: .utf8) else { + XCTFail("Failed to get the answer") + return + } + + XCTAssertEqual(decompressedString, answerString, "Decompression was incorrect") } } diff --git a/Tests/Test Files/BZip2/test1.bz2 b/Tests/Test Files/BZip2/test1.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..22fc2f24100610c8d6dcfda35d11aea5733fe4af GIT binary patch literal 58 zcmZ>Y%CIzaj8qGboVi9RjDdkEyn#U=frY_=p@EHM0)qmB5?kYhhRkK15?SY#NalC% ORGOpV;d4z;n*jjMj}ZI- literal 0 HcmV?d00001 diff --git a/Tests/Test Files/BZip2/test2.bz2 b/Tests/Test Files/BZip2/test2.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..7dd4fa61d21bdef65207ea934e34203c27d004cc GIT binary patch literal 802 zcmV+-1Ks>WT4*^jL0KkKS<4T5aR2~^Uw{A-00DiVJ?7lBzyJU6Py^YwjSfHn2B)Z+ zYBXU6nl#X40LG!}WCo@M6KWoy0000007`mQGJ_-3$)M0^Xvv@hOqvV;13&;|&;S5v z1WG1ANswranNLhpH4QO6O_cQ#s)OhB`gScSt5PyBgcT4`B#e=zQZk_yN+Bk@`}fO| z+jw}abXXsMlY#C)WDuZWyzw|AmD&WZGbmLwd5|+yVbP34;G8MFFFFj2Bw#KumH<)c zfk9J9URnYWfELvS!;ajSBLdM+`lL!Um}kEC!n~JCK(t0hF@e3y(2;=>a$t?(kbnUQ z8Iek5LtuzutDuz^R>c4gseuZ59NG`+!=wNZ6jEr;Mue{?Wl+veMnH%k$N@V{5duU= zZZk+Z#!R777nP<;V}q#+k;Gur5{4{hAc113sR=L$m(*ys7??#N1{9oXNMb4$!qW-a zeTKC;&2sw>;7?q2ArH^+e_p^LcIob>p#FiZK>LQsW<4b2-SZ2R7y+Ze&xgdSpu`^F z30SwfD+XH5!9uTH)d>Xx5RI4$s^h(F7*O0H5RjxyAO!q}9?S*ksCZx;2jGXbMMB6Q zK=nCyq0k2P-NWW?6$+N8c)P`5>>i?O9B-?btw%F@I{R+}j|TwWJp+)aY2#=hlzg@m zoNJyVkITeE{lqwjjzS4hsL@Wo8iaaxK=&xziKskmJy8n<1QT+XD9jZ@i)qdQK~U}m z&;%!Vtz;fM5Wf*9&Vvw2c`+jES`y@r`h}9+$Slp*9KgIAvh5+yWEK55aNNT-9hA6v%Xg19+K- glCE?!`U>)nk>=$J)la&cDgTSPBAh5lWrw}EfSiI`)Bpeg literal 0 HcmV?d00001 diff --git a/Tests/Test Files/BZip2/test3.bz2 b/Tests/Test Files/BZip2/test3.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..6889d32b239e3246d172e5d60cf170ad29cb30d3 GIT binary patch literal 835 zcmV-J1HAk~T4*^jL0KkKSv=&19RLNU-+%xT00A%nKj;30zyJU6Py`sf00006NRwoZ z2dU~b#4-RqO{4(84K!#p!~g&TAO@b5GMOi!n1O(rVLd_U(rJtU(?)|#KmY(T07Rgg zOj8JIGMR+UNuV-%H3&)){^|fEAdl9@HsPQc3?a0{#)Kjm(E8!+zcFFYCvYY|U(-Ixy&f_Nu|x17cI3Y%CIzaj8qGbJa=~8Y6eEb0k literal 0 HcmV?d00001 diff --git a/Tests/Test Files/BZip2/test5.bz2 b/Tests/Test Files/BZip2/test5.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..b56f3b974d6a345462b5a64b15a84c9b23bb40ec GIT binary patch literal 14 TcmZ>Y%CHnKa