//
// Created by alex on 7/31/17.
//
#include "cpp_solutions/chapter_01_arrays_and_strings/chapter_01_includes.h"
#include "cpp_solutions/chapter_02_linked_lists/chapter_02_includes.h"
#include "cpp_solutions/chapter_03_stacks_and_queues/chapter_03_includes.h"
#include "cpp_solutions/chapter_04_trees_and_graphs/chapter_04_includes.h"
#include "cpp_solutions/chapter_05_bit_manipulation/chapter_05_includes.h"
#include "cpp_solutions/chapter_08_recursion_and_dynamic_programming/chapter_08_includes.h"
#include "cpp_solutions/chapter_10_sorting_and_searching/chapter_10_includes.h"
#include "cpp_solutions/chapter_12_cpp/chapter_12_includes.h"
#include "cpp_solutions/misc_exercises/misc_includes.h"
#define CATCH_CONFIG_MAIN
#include "cpp_solutions/third_party/Catch/include/catch.hpp"
#include
#include
#include
TEST_CASE("Chapter 01 - Problem 01 - isUnique()", "test"){
REQUIRE(chapter_01::isUnique("alex"));
REQUIRE(!chapter_01::isUnique("aalex"));
}
TEST_CASE("Chapter 01 - Problem 02 - isPermutation()", "test"){
REQUIRE(!chapter_01::isPermutation("alex", "aalex"));
REQUIRE(chapter_01::isPermutation("alex", "xela"));
REQUIRE(!chapter_01::isPermutation("aabb", "aaaa"));
REQUIRE(!chapter_01::isPermutation("aaaa", "aabb"));
REQUIRE(!chapter_01::isPermutation("aaaa", "aa"));
REQUIRE(chapter_01::isPermutation("", ""));
}
TEST_CASE("Chapter 01 - Problem 03 - URLify()", "test") {
// expect 'Mr. John Smith' -> 'Mr.%20John%20Smith'
std::string input1 = "Mr. John Smith ";
std::string output1 = "Mr.%20John%20Smith%20";
chapter_01::URLify(input1);
REQUIRE(input1 == output1);
std::string input2 = "";
std::string output2 = "";
chapter_01::URLify(input2);
REQUIRE(input2 == output2);
std::string input3 = " ";
std::string output3 = "%20";
chapter_01::URLify(input3);
REQUIRE(input3 == output3);
std::string input4 = "Alex";
std::string output4 = "Alex";
chapter_01::URLify(input4);
REQUIRE(input4 == output4);
}
TEST_CASE("Chapter 01 - Problem 04 - palindromePermutation()", "test") {
REQUIRE(chapter_01::palindromePermutation("tact coa"));
REQUIRE(!chapter_01::palindromePermutation("Tact Coa"));
REQUIRE(!chapter_01::palindromePermutation("xyz"));
REQUIRE(chapter_01::palindromePermutation("AA B AA"));
REQUIRE(!chapter_01::palindromePermutation("aA B AA"));
}
TEST_CASE("Chapter 01 - Problem 05 - oneAway()", "test"){
REQUIRE(chapter_01::oneAway("pale", "ple"));
REQUIRE(chapter_01::oneAway("pale", "pale"));
REQUIRE(chapter_01::oneAway("pale", "bale"));
REQUIRE(!chapter_01::oneAway("pale", "bae"));
REQUIRE(!chapter_01::oneAway("alex", "al"));
REQUIRE(!chapter_01::oneAway("alex", "all"));
REQUIRE(!chapter_01::oneAway("alex", "alll"));
REQUIRE(chapter_01::oneAway("apple", "aple"));
REQUIRE(chapter_01::oneAway("bale", "pale"));
REQUIRE(chapter_01::oneAway("", ""));
}
TEST_CASE("Chapter 01 - Problem 06 - stringCompression()", "test"){
REQUIRE("a2b1c5a3" == chapter_01::stringCompression("aabcccccaaa"));
REQUIRE("alex" == chapter_01::stringCompression("alex"));
REQUIRE("" == chapter_01::stringCompression(""));
REQUIRE("a10" == chapter_01::stringCompression("aaaaaaaaaa"));
}
TEST_CASE("Chapter 01 - Problem 07 - rotateMatrix()", "test"){
Eigen::MatrixXi input4x4(4,4);
input4x4