#include <jsonincpp/jsonobj.h>
#include <jsonincpp/string_representation.h>
#include <assert.h>

using namespace json;

void prettyprint_json(const JSON& obj) {
    printf("%s", generate_str(obj, print_pretty).c_str());
}

void test2(const JSON& A, const JSON& B, bool answer) {
    if ((A == B) == answer)
        printf("Test passed\n");
    else {
        fprintf(stderr, "Test failed");
        abort();
    }
}

void test(const JSON& A, const JSON& B, bool answer) {
    test2(A, B, answer);
    test2(B, A, answer);
}

void test_obvious(const JSON& A) {
    test(A, A, true);
    JSON B = A;
    test(B, A, true);
    /* Let's get real */
    JSON big;
    big[1] = A;
    test(big, A, false);
    big[0] = A;
    test(big[0], big[1], true);
}

void ftest(int i) {
    JSON A;
    JSON B;
    A["aaa"][(size_t)i]["bbb"].asArray().push_back(JSON(jarr{JSON("Hihi"), JSON("Haha")}));
    A["aaa"][i]["bbb"][4]["hihi"].asInteger() = Integer(4123);
    B.asDictionary()["aaa"][(size_t)i].asDictionary()["bbb"][0][0].asString() = "Hihi";
    B.asDictionary()["aaa"][(size_t)i].asDictionary()["bbb"][0][1].asString() = "Haha";
    B["aaa"].asArray()[i]["bbb"][4].asDictionary()["hihi"] = JSON(4123l);
    prettyprint_json(A);
    prettyprint_json(B);
    test(A, B, true);
}

int main(){
    json::JSON A;
    A[1].asString();
    A[0].asInteger();
    json::JSON B;
    B[0].asInteger();
    B[1].asString();
    test(A, B, true);
    return 0;
    test_obvious(parse_str_flawless("{ \"aaa\": true, \"2\":[true]}"));
    test_obvious(parse_str_flawless("{ \"aa\": true, \"tttt\": [true, false]}"));
    test_obvious(parse_str_flawless("[[[]]]"));
    test_obvious(parse_str_flawless("[[[\"asdasdasdasd\", {\"aaa\" : 12311, \"\":\"\"}]]]"));
    test(parse_str_flawless("1321231231231231231231231231231231"), parse_str_flawless("-132123123123123123123123123123123123"), false);
    test(parse_str_flawless("1321231231231231231231231231231231"), parse_str_flawless("-132123123123123123123.123123123123123"), false);
    test(parse_str_flawless("999999999999999999"), parse_str_flawless("999999999999999999"), true);
    test(parse_str_flawless("9999999999999999999"), parse_str_flawless("9999999999999999999"), true);
    test(parse_str_flawless("132123123123123123123123123123123123"), parse_str_flawless("132123123123123123123123123123123123"), true);
    test(parse_str_flawless("{}"), parse_str_flawless("{}"), true);
    test(parse_str_flawless("{}"), parse_str_flawless("true"), false);
    for (int i = 0; i < 100; i += 10) {
        ftest(i);
    }
    return 0;
}