forked from probsys/hierarchical-irm
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from probcomp/061724-thomaswc-getemission
Add get_emission
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 | ||
// See LICENSE.txt | ||
|
||
#include "emissions/get_emission.hh" | ||
|
||
#include <cassert> | ||
|
||
#include "emissions/bitflip.hh" | ||
#include "emissions/gaussian.hh" | ||
#include "emissions/simple_string.hh" | ||
|
||
EmissionVariant get_emission(const std::string& emission_name) { | ||
if (emission_name == "gaussian") { | ||
return new GaussianEmission(); | ||
} else if (emission_name == "simple_string") { | ||
return new SimpleStringEmission(); | ||
} else if (emission_name == "sometimes_gaussian") { | ||
return new SometimesGaussian(); | ||
} else if (emission_name == "sometimes_bitflip") { | ||
return new SometimesBitFlip(); | ||
} | ||
printf("Unknown emission name %s\n", emission_name.c_str()); | ||
assert(false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2024 | ||
// See LICENSE.txt | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <variant> | ||
|
||
#include "emissions/sometimes.hh" | ||
|
||
class BitFlip; | ||
class GaussianEmission; | ||
class SimpleStringEmission; | ||
using SometimesBitFlip = Sometimes<BitFlip, bool>; | ||
using SometimesGaussian = Sometimes<GaussianEmission, double>; | ||
|
||
using EmissionVariant = std::variant<GaussianEmission*, SometimesGaussian*, | ||
SometimesBitFlip*, SimpleStringEmission*>; | ||
|
||
EmissionVariant get_emission(const std::string& emission_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#define BOOST_TEST_MODULE test get_emission | ||
|
||
#include "emissions/get_emission.hh" | ||
|
||
#include <boost/test/included/unit_test.hpp> | ||
|
||
#include "emissions/bitflip.hh" | ||
#include "emissions/gaussian.hh" | ||
#include "emissions/simple_string.hh" | ||
|
||
BOOST_AUTO_TEST_CASE(test_get_emission_gaussian) { | ||
EmissionVariant ev = get_emission("gaussian"); | ||
GaussianEmission* ge = std::get<GaussianEmission*>(ev); | ||
|
||
ge->incorporate(std::make_pair<double, double>(2.0, 2.1)); | ||
BOOST_TEST(ge->N == 1); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_get_emission_simple_string) { | ||
EmissionVariant ev = get_emission("simple_string"); | ||
SimpleStringEmission* sse = std::get<SimpleStringEmission*>(ev); | ||
|
||
sse->incorporate(std::make_pair<std::string, std::string>("hello", "hi")); | ||
BOOST_TEST(sse->N == 1); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_get_emission_sometimes_gaussian) { | ||
EmissionVariant ev = get_emission("sometimes_gaussian"); | ||
SometimesGaussian* sg = std::get<SometimesGaussian*>(ev); | ||
|
||
sg->incorporate(std::make_pair<double, double>(2.0, 2.1)); | ||
BOOST_TEST(sg->N == 1); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_get_emission_sometimes_bitflip) { | ||
EmissionVariant ev = get_emission("sometimes_bitflip"); | ||
SometimesBitFlip* sbf = std::get<SometimesBitFlip*>(ev); | ||
|
||
sbf->incorporate(std::make_pair<bool, bool>(true, true)); | ||
BOOST_TEST(sbf->N == 1); | ||
} |