Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#define Assert(ex) assert(test_name.c_str() && (ex)) #define TEST(title) test_name = (title); #include "func.h" char RndLetter() { return (rand() % 26) + 'a'; } int RndInt(int l, int r) { return (rand() % (r - l + 1)) + l; } int main() { int test; std::cin >> test; std::string test_name; srand(test); TEST("not serializable") { std::set
not_working; not_working.insert(1); not_working.insert(2); not_working.insert(2); Assert(Serialize(not_working) == ""); } TEST("string serialize") { std::string name = "Dasha"; Assert(Serialize(name) == "\"Dasha\""); } std::vector
names; TEST("random strings") { int q = (test == 0 ? 10 : 100); for (size_t i = 0; i < q; ++i) { int size = (rand() % 7) + 5; std::string name(size, '\0'); for (size_t j = 0; j < size; ++j) { name[j] = RndLetter(); } Assert(Serialize(name) == "\"" + name + "\""); names.push_back(name); } } TEST("vector check") { std::vector
numbers = {1, 2, 3}; Assert(Serialize(numbers) == "[1,2,3]"); std::vector
strings = {"a", "bb", "ccc"}; Assert(Serialize(strings) == "[\"a\",\"bb\",\"ccc\"]"); std::vector
empty; Assert(Serialize(empty) == "[]"); } TEST("map check") { std::map
test_map = {{1, "one"}, {2, "two"}}; Assert(Serialize(test_map) == "{1:\"one\",2:\"two\"}"); std::map
string_keys = {{"a", 1}, {"b", 2}}; Assert(Serialize(string_keys) == "{\"a\":1,\"b\":2}"); std::map
empty_map; Assert(Serialize(empty_map) == "{}"); } TEST("nested structures") { std::vector
> nested = { {{1, "a"}, {2, "b"}}, {{3, "c"}, {4, "d"}} }; // std::cout << Serialize(nested) << '\n'; Assert(Serialize(nested) == "[{1:\"a\",2:\"b\"},{3:\"c\",4:\"d\"}]"); std::map
> map_with_vectors = { {"odds", {1, 3, 5}}, {"evens", {2, 4, 6}} }; Assert(Serialize(map_with_vectors) == "{\"evens\":[2,4,6],\"odds\":[1,3,5]}"); } TEST("int serialize") { Assert(Serialize(42) == "42"); Assert(Serialize(-10) == "-10"); Assert(Serialize(0) == "0"); } TEST("empty collections") { std::vector
empty_vec; std::map
empty_map; std::vector
> empty_nested; Assert(Serialize(empty_vec) == "[]"); Assert(Serialize(empty_map) == "{}"); Assert(Serialize(empty_nested) == "[]"); } TEST("single element collections") { std::vector
single = {42}; std::map
single_map = {{1, "one"}}; Assert(Serialize(single) == "[42]"); Assert(Serialize(single_map) == "{1:\"one\"}"); } std::cout << "All tests passed!" << std::endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)