-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: LZW | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: build | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
test: | ||
name: test | ||
runs-on: ubuntu-latest | ||
|
||
needs: build | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run tests | ||
run: | | ||
cd tests | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make lzw_test | ||
./lzw_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(LZW_CPP) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
add_library(LZW STATIC src/LZW.cpp src/LZW.h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(LZWTest) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip | ||
) | ||
|
||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
enable_testing() | ||
|
||
add_executable(lzw_test test.cpp ../src/LZW.cpp) | ||
|
||
target_link_libraries(lzw_test GTest::gtest_main) | ||
|
||
include(GoogleTest) | ||
gtest_discover_tests(lzw_test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "../src/LZW.h" | ||
#include <chrono> | ||
#include <gtest/gtest.h> | ||
#include <iostream> | ||
#include <random> | ||
|
||
TEST(LZWTest, CompressionAndDecompression) | ||
{ | ||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count()); | ||
std::mt19937 rng(seed); | ||
std::uniform_int_distribution<int> distribution(0, 255); | ||
std::string input1; | ||
std::string input2; | ||
std::string input3; | ||
std::string input4; | ||
|
||
for (int i = 1; i <= 1000000; ++i) { | ||
input1 += static_cast<char>(distribution(rng)); | ||
input2 += static_cast<char>(distribution(rng) % 128); | ||
input3 += static_cast<char>(i % 256); | ||
input4 += static_cast<char>(100); | ||
} | ||
|
||
auto [compressResult1, compressCode1] = sLZW->Compress(input1); | ||
ASSERT_EQ(compressCode1, LZW_OK); | ||
auto [compressResult2, compressCode2] = sLZW->Compress(input2); | ||
ASSERT_EQ(compressCode2, LZW_OK); | ||
auto [compressResult3, compressCode3] = sLZW->Compress(input3); | ||
ASSERT_EQ(compressCode3, LZW_OK); | ||
auto [compressResult4, compressCode4] = sLZW->Compress(input4); | ||
ASSERT_EQ(compressCode4, LZW_OK); | ||
|
||
auto [decompressResult1, decompressCode1] = sLZW->Decompress(compressResult1); | ||
ASSERT_EQ(decompressCode1, LZW_OK); | ||
auto [decompressResult2, decompressCode2] = sLZW->Decompress(compressResult2); | ||
ASSERT_EQ(decompressCode2, LZW_OK); | ||
auto [decompressResult3, decompressCode3] = sLZW->Decompress(compressResult3); | ||
ASSERT_EQ(decompressCode3, LZW_OK); | ||
auto [decompressResult4, decompressCode4] = sLZW->Decompress(compressResult4); | ||
ASSERT_EQ(decompressCode4, LZW_OK); | ||
|
||
ASSERT_EQ(decompressResult1, input1); | ||
ASSERT_EQ(decompressResult2, input2); | ||
ASSERT_EQ(decompressResult3, input3); | ||
ASSERT_EQ(decompressResult4, input4); | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |