// Step 450: Algorithm-Level Equivalence Tests (12 tests) #include "AlgorithmEquivalence.h" #include static int passed = 0, failed = 0; #define TEST(name) { std::cout << " " << #name << "... "; } #define PASS() { std::cout << "PASS\n"; ++passed; } #define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; } #define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } else {} void test_detect_bubble_sort() { TEST(detect_bubble_sort); std::string src = "for(i=0;ia[j+1]) swap(a[j],a[j+1]);"; auto r = AlgorithmRecognizer::analyze(src, "c", "rust"); CHECK(r.hasPattern("bubble_sort"), "expected bubble_sort pattern"); PASS(); } void test_sort_maps_to_stdlib() { TEST(sort_maps_to_stdlib); std::string src = "for(i=0;ia[j+1]) swap(a[j],a[j+1]);"; auto r = AlgorithmRecognizer::analyze(src, "c", "rust"); auto eq = r.equivalentFor("bubble_sort"); CHECK(eq.usesStdLib, "sort should map to stdlib"); CHECK(eq.targetCode.find("sort") != std::string::npos, "should use .sort()"); PASS(); } void test_detect_linear_search() { TEST(detect_linear_search); std::string src = "for(int i=0;i= 2, "expected at least 2 stdlib equivalents"); PASS(); } void test_supported_patterns_list() { TEST(supported_patterns_list); auto patterns = AlgorithmRecognizer::supportedPatterns(); CHECK(patterns.size() >= 15, "expected at least 15 supported patterns"); PASS(); } void test_cross_language_sort_targets() { TEST(cross_language_sort_targets); std::string src = "for(i=0;ia[j+1]) swap(a[j],a[j+1]);"; auto r1 = AlgorithmRecognizer::analyze(src, "c", "python"); auto r2 = AlgorithmRecognizer::analyze(src, "c", "java"); auto eq1 = r1.equivalentFor("bubble_sort"); auto eq2 = r2.equivalentFor("bubble_sort"); CHECK(eq1.targetCode.find("sorted") != std::string::npos, "Python should use sorted()"); CHECK(eq2.targetCode.find("Collections.sort") != std::string::npos, "Java should use Collections.sort"); PASS(); } int main() { std::cout << "Step 450: Algorithm-Level Equivalence Tests\n"; test_detect_bubble_sort(); // 1 test_sort_maps_to_stdlib(); // 2 test_detect_linear_search(); // 3 test_detect_binary_search(); // 4 test_detect_key_lookup(); // 5 test_detect_manual_map(); // 6 test_detect_manual_filter(); // 7 test_detect_manual_reduce(); // 8 test_detect_builder_pattern(); // 9 test_stdlib_count(); // 10 test_supported_patterns_list(); // 11 test_cross_language_sort_targets(); // 12 std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n"; return failed == 0 ? 0 : 1; }