Sprint 288: LibrarySymbolAdvisor (steps 1968-1972)
Specific API symbol recommendation layer. Five new headers: - LibrarySymbolRecord: functionName/signature/usagePattern/caveats - LibrarySymbolCatalog: multi-symbol registry per (library, domain) - LSPSymbolExtractor: parses LSP JSON into LibrarySymbolRecords - LibrarySymbolAdvisor: ranked symbols for (library, domain) alphabetically - Sprint288IntegrationSummary: CUDA+nlohmann catalog; cublasSgemm+json::parse verified 25/25 tests passing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
86
editor/tests/step1969_test.cpp
Normal file
86
editor/tests/step1969_test.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
// Step 1969: LibrarySymbolCatalog
|
||||
//
|
||||
// t1: add and has
|
||||
// t2: get returns all records for (library, domain)
|
||||
// t3: get returns empty for unknown pair
|
||||
// t4: allForLibrary and allForDomain
|
||||
// t5: size counts total records across all keys
|
||||
|
||||
#include "LibrarySymbolCatalog.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace ws = whetstone;
|
||||
static int p = 0, f = 0;
|
||||
#define T(n) { std::cout << " " << #n << "... "; }
|
||||
#define P() { std::cout << "PASS\n"; ++p; }
|
||||
#define F(m) { std::cout << "FAIL: " << m << "\n"; ++f; }
|
||||
#define C(c, m) if (!(c)) { F(m); return; }
|
||||
|
||||
static ws::LibrarySymbolCatalog makeCatalog() {
|
||||
ws::LibrarySymbolCatalog cat;
|
||||
cat.add({"cublas", "cublasSgemm", "sig_sgemm", "compute.matrix", "", {}});
|
||||
cat.add({"cublas", "cublasDgemm", "sig_dgemm", "compute.matrix", "", {}});
|
||||
cat.add({"nlohmann_json", "json::parse", "sig_parse", "serialization.json", "", {}});
|
||||
cat.add({"nlohmann_json", "json::dump", "sig_dump", "serialization.json", "", {}});
|
||||
cat.add({"thrust", "thrust::sort", "sig_sort", "compute.parallel", "", {}});
|
||||
return cat;
|
||||
}
|
||||
|
||||
void t1() {
|
||||
T(add_and_has);
|
||||
ws::LibrarySymbolCatalog cat;
|
||||
C(!cat.has("cublas", "compute.matrix"), "not present before add");
|
||||
cat.add({"cublas", "cublasSgemm", "sig", "compute.matrix", "", {}});
|
||||
C(cat.has("cublas", "compute.matrix"), "present after add");
|
||||
C(!cat.has("cublas", "serialization.json"), "different domain not present");
|
||||
P();
|
||||
}
|
||||
|
||||
void t2() {
|
||||
T(get_returns_all_for_pair);
|
||||
auto cat = makeCatalog();
|
||||
auto cublas_matrix = cat.get("cublas", "compute.matrix");
|
||||
C(cublas_matrix.size() == 2, "2 cublas/compute.matrix records");
|
||||
auto nlohmann_json = cat.get("nlohmann_json", "serialization.json");
|
||||
C(nlohmann_json.size() == 2, "2 nlohmann/serialization.json records");
|
||||
P();
|
||||
}
|
||||
|
||||
void t3() {
|
||||
T(get_returns_empty_for_unknown_pair);
|
||||
auto cat = makeCatalog();
|
||||
auto none = cat.get("unknown_lib", "compute.matrix");
|
||||
C(none.empty(), "empty for unknown library");
|
||||
auto none2 = cat.get("cublas", "serialization.json");
|
||||
C(none2.empty(), "empty for domain cublas has no symbols in");
|
||||
C(!cat.has("cublas", "serialization.json"), "has() false");
|
||||
P();
|
||||
}
|
||||
|
||||
void t4() {
|
||||
T(allForLibrary_and_allForDomain);
|
||||
auto cat = makeCatalog();
|
||||
auto cublas_all = cat.allForLibrary("cublas");
|
||||
C(cublas_all.size() == 2, "2 cublas records total");
|
||||
auto matrix_all = cat.allForDomain("compute.matrix");
|
||||
C(matrix_all.size() == 2, "2 compute.matrix records");
|
||||
auto thrust_all = cat.allForLibrary("thrust");
|
||||
C(thrust_all.size() == 1, "1 thrust record");
|
||||
P();
|
||||
}
|
||||
|
||||
void t5() {
|
||||
T(size_counts_all_records);
|
||||
auto cat = makeCatalog();
|
||||
C(cat.size() == 5, "5 total records, got " + std::to_string(cat.size()));
|
||||
ws::LibrarySymbolCatalog empty;
|
||||
C(empty.size() == 0, "empty catalog size 0");
|
||||
P();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Step 1969: LibrarySymbolCatalog\n";
|
||||
t1(); t2(); t3(); t4(); t5();
|
||||
std::cout << "\n" << p << "/" << (p + f) << " passed\n";
|
||||
return f > 0 ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user