feat: scaffold FCES-native C++ project with libtorch integration
- CMakeLists.txt with libtorch, GoogleTest, GoogleBenchmark, OpenMP, pybind11 - Header files: config, controller, population, fitness, evolution, spectral, oscillation, telemetry, optimizer - Source implementations: controller (full micro-MLP forward pass, mutation, crossover), fitness (Welford's algorithm), oscillation (DFT), spectral (SVD rank), optimizer (sign-SGD stub) - Tests: controller, population, fitness, optimizer (Google Test) - Benchmarks: evolve throughput, optimizer step (Google Benchmark) - Examples: simple optimization, PyTorch/libtorch integration - Python extension: pybind11 bindings with setup.py - README with architecture diagram and build instructions
This commit is contained in:
58
tests/test_controller.cpp
Normal file
58
tests/test_controller.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "fces/controller.hpp"
|
||||
|
||||
using namespace fces;
|
||||
|
||||
TEST(ControllerTest, Construction) {
|
||||
FuzzyController ctrl;
|
||||
EXPECT_GT(ctrl.id, 0u);
|
||||
EXPECT_EQ(ctrl.fitness, 0.0f);
|
||||
EXPECT_EQ(ctrl.origin, "random");
|
||||
}
|
||||
|
||||
TEST(ControllerTest, GenomeSize) {
|
||||
FuzzyController ctrl;
|
||||
EXPECT_EQ(ctrl.genome.weights.size(), static_cast<size_t>(GENOME_SIZE));
|
||||
}
|
||||
|
||||
TEST(ControllerTest, Mutation) {
|
||||
FuzzyController parent;
|
||||
auto child = parent.mutate(1.0f);
|
||||
EXPECT_NE(child.id, parent.id);
|
||||
EXPECT_EQ(child.origin, "mutation");
|
||||
// Child should differ from parent
|
||||
bool differs = false;
|
||||
for (size_t i = 0; i < parent.genome.weights.size(); ++i) {
|
||||
if (parent.genome.weights[i] != child.genome.weights[i]) {
|
||||
differs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(differs);
|
||||
}
|
||||
|
||||
TEST(ControllerTest, Crossover) {
|
||||
FuzzyController a, b;
|
||||
auto child = a.crossover(b);
|
||||
EXPECT_EQ(child.origin, "crossover");
|
||||
}
|
||||
|
||||
TEST(ControllerTest, DecideUpdate) {
|
||||
FuzzyController ctrl;
|
||||
std::vector<std::vector<float>> stats = {{0.1f, 0.2f, 0.3f, 0.4f, 0.5f}};
|
||||
auto actions = ctrl.decide_update(stats, 0.0f, 0.5f, 0.0f, 0.1f, 0.0f, 0.0f, 1.0f, 0.0f);
|
||||
EXPECT_EQ(actions.size(0), 1);
|
||||
EXPECT_EQ(actions.size(1), GENOME_OUTPUT_DIM);
|
||||
}
|
||||
|
||||
TEST(ControllerTest, OrthogonalChild) {
|
||||
FuzzyController parent;
|
||||
auto child = parent.create_orthogonal_child(1.0f);
|
||||
EXPECT_EQ(child.origin, "phoenix_rebirth");
|
||||
}
|
||||
|
||||
TEST(ControllerTest, BanachFission) {
|
||||
FuzzyController parent;
|
||||
auto [plus, minus] = parent.banach_tarski_fission(1.0f);
|
||||
EXPECT_NE(plus.id, minus.id);
|
||||
}
|
||||
Reference in New Issue
Block a user