<commit_before>//
// Created by Sam on 10/7/2017.
//

#include "../../../build/catch-src/include/catch.hpp"
#include "../../../include/Network/Message.h"


TEST_CASE("Verify JSON format")
{
    std::string correctJSON = R"({"type":"test","data":"Does this test pass?"})";

    Message message("test", "Does this test pass?");
    std::string createdJSON = message.exportJSON();

    REQUIRE(correctJSON == createdJSON);
}

TEST_CASE("Parsing JSON")
{
    std::string type = "test";
    std::string data = "Does this test pass?";
    std::string correctJSON = R"({"type":")" + type + R"(","data":")" + data + R"("})";

    Message message(correctJSON);

    REQUIRE(message.type == type);
    REQUIRE(message.data == data);
}
<commit_msg>Added some unit tests for creating and parsing an example JSON message.<commit_after>//
// Created by Sam on 10/7/2017.
//

#include "../../../build/catch-src/include/catch.hpp"
#include "../../../include/Network/Message.h"
#include <iostream>


TEST_CASE("Build JSON")
{
    std::string typeKey = "type";
    std::string typeValue = "Test";
    std::string dataKey = "data";
    std::string dataMemberKey = "name";
    std::string dataMemberValue = "Sam";

    // {"type":"Test","data":{"name":"Sam"}}
    std::string json = "{\"" + typeKey + "\":\"" + typeValue +
            "\",\"" + dataKey + "\":{\"" + dataMemberKey + "\":\"" + dataMemberValue +"\"}}";

    Message message("Test");
    message.addDataMember("name", "Sam");
    std::string result = message.getJSON();
    std::string type = message.getMember("type");
    std::string name = message.getDataMember("name");

    REQUIRE(type == typeValue);
    REQUIRE(dataMemberValue == name);
    REQUIRE(result == json);
}

TEST_CASE("Parse JSON")
{
    std::string typeKey = "type";
    std::string typeValue = "Test";
    std::string dataKey = "data";
    std::string dataMemberKey = "name";
    std::string dataMemberValue = "Sam";

    // {"type":"Test","data":{"name":"Sam"}}
    std::string json = "{\"" + typeKey + "\":\"" + typeValue +
                       "\",\"" + dataKey + "\":{\"" + dataMemberKey + "\":\"" + dataMemberValue +"\"}}";

    Message loaded;
    loaded.loadJSON(json);

    std::string result = loaded.getJSON();
    std::string type = loaded.getMember("type");
    std::string name = loaded.getDataMember("name");
    
    REQUIRE(type == typeValue);
    REQUIRE(name == dataMemberValue);
    REQUIRE(result == json);
}
{'fraction_non_alphanumeric': 0.21563011456628478, 'fraction_numerical': 0.0057283142389525366, 'mean_word_length': 3.3045774647887325, 'pattern_counts': {'":': 16, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4987350', 'n_tokens_mistral': 806, 'n_tokens_neox': 776, 'n_words': 164}