MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / notes_test

Function notes_test

Tests/notes_test.h:45–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 * ( cd test_data && ../gen_note_events.py note_events.input.json notes.csv onsets.csv contours.csv note_events.output.json )
44 */
45bool notes_test()
46{
47 // inputs are the model's output + JSON params
48 std::ifstream f_notes_pg(std::string(TEST_DATA_DIR) + "/notes.csv");
49 std::ifstream f_onsets_pg(std::string(TEST_DATA_DIR) + "/onsets.csv");
50 std::ifstream f_contours_pg(std::string(TEST_DATA_DIR) + "/contours.csv");
51 auto notes_pg_1d = test_utils::loadCSVDataFile<float>(f_notes_pg);
52 auto onsets_pg_1d = test_utils::loadCSVDataFile<float>(f_onsets_pg);
53 auto contours_pg_1d = test_utils::loadCSVDataFile<float>(f_contours_pg);
54
55 std::ifstream f_input(std::string(TEST_DATA_DIR) + "/note_events.input.json");
56 std::ifstream f_expected(std::string(TEST_DATA_DIR) + "/note_events.output.json");
57 auto all_cases = json::parse(f_input).get<std::vector<Notes::ConvertParams>>();
58 auto all_expected = json::parse(f_expected).get<std::vector<std::vector<Notes::Event>>>();
59 assert(all_cases.size() == all_expected.size());
60
61 auto notes_pg = test_utils::convert_1d_to_2d<float>(notes_pg_1d, -1, NUM_FREQ_OUT);
62 auto onsets_pg = test_utils::convert_1d_to_2d<float>(onsets_pg_1d, -1, NUM_FREQ_OUT);
63 auto contours_pg = test_utils::convert_1d_to_2d<float>(contours_pg_1d, -1, NUM_FREQ_IN);
64
65 Notes n;
66 bool succeeded = true;
67 for (int i = 0; i < all_cases.size() && succeeded; i++) {
68 auto params = all_cases[i];
69 auto expected = all_expected[i];
70 std::cout << " Case " << i << ": ";
71 auto start_time = std::chrono::high_resolution_clock::now();
72 auto note_events = n.convert(notes_pg, onsets_pg, contours_pg, params);
73 auto stop_time = std::chrono::high_resolution_clock::now();
74 std::chrono::duration<double> duration = stop_time - start_time;
75 std::cout << "done in " << duration.count() << " seconds" << std::endl;
76
77 if (note_events.size() != expected.size()) {
78 std::cout << "FAIL: Got " << note_events.size() << " elements in array, expected " << expected.size()
79 << std::endl;
80 succeeded = false;
81 }
82
83 for (int j = 0; j < expected.size(); j++) {
84 if (!(note_events[j] == expected[j])) {
85 json res = note_events[j];
86 json exp = expected[j];
87 std::cout << "FAIL: Element " << j << " is:" << std::endl
88 << "\t" << res << std::endl
89 << "Expecting:" << std::endl
90 << "\t" << exp << std::endl;
91 succeeded = false;
92 }
93 }
94 }
95 if (succeeded) {
96 std::cout << "Success" << std::endl;
97 }
98 return succeeded;
99}
100
101#endif //NN_NOTES_TEST_H

Callers 1

mainFunction · 0.85

Calls 1

convertMethod · 0.80

Tested by

no test coverage detected