<commit_before>#include <catch.hpp>

#include "simulation.hpp"

TEST_CASE("SpeciesReaction methods", "[Reaction]") {
  auto reaction = std::make_shared<SpeciesReaction>(
      1000, std::vector<std::string>{"reactant1", "reactant2"},
      std::vector<std::string>{"product1", "product2"});
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  tracker.Register(reaction);
  tracker.Increment("reactant1", 2);
  tracker.Increment("reactant2", 3);

  SECTION("Initialization and registration") {
    REQUIRE_THROWS(SpeciesReaction(
        1000, std::vector<std::string>{"reactant1", "reactant2", "reactant3"},
        std::vector<std::string>{"product1", "product2"}));
    // Make sure that maps have been set up appropriately
    auto reactions = tracker.FindReactions("reactant1");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("reactant2");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("product1");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("product2");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
  }

  SECTION("Propensity calculation") {
    REQUIRE((1000 * 2 * 3) / (double(6.0221409e+23) * double(8e-15)) ==
            reaction->CalculatePropensity());
  }

  SECTION("Execution") {
    reaction->Execute();
    REQUIRE(tracker.species("reactant1") == 1);
    REQUIRE(tracker.species("reactant2") == 2);
    REQUIRE(tracker.species("product1") == 1);
    REQUIRE(tracker.species("product1") == 1);
  }
}

TEST_CASE("Bind methods", "[Reaction]") {
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  // Set up a polymer
  std::vector<std::string> interactions = {"ecolipol"};
  Promoter::Ptr prom;
  Terminator::Ptr term;
  prom = std::make_shared<Promoter>("p1", 5, 15, interactions);
  std::map<std::string, double> efficiency;
  efficiency["ecolipol"] = 0.6;
  term = std::make_shared<Terminator>("t1", 50, 55, interactions, efficiency);

  std::vector<Element::Ptr> elements;
  elements.push_back(prom);
  elements.push_back(term);
  std::vector<std::string> mask_interactions = {"ecolipol"};
  Mask mask = Mask("test_mask", 50, 100, mask_interactions);

  auto polymer =
      std::make_shared<Polymer>("test_polymer", 1, 100, elements, mask);
  // Set up a polymerase
  auto polymerase = Polymerase("ecolipol", 10, 30);
  auto reaction = Bind(1000, "p1", polymerase);

  SECTION("Calculate propensity") {
    tracker.Increment("p1", 2);
    tracker.Increment("ecolipol", 3);
    REQUIRE((1000 * 2 * 3) / (double(6.0221409e+23) * double(8e-15)) ==
            reaction.CalculatePropensity());
  }

  SECTION("Execution") {
    tracker.Clear();
    tracker.Increment("p1", 1);
    tracker.Increment("ecolipol", 1);
    tracker.Add("p1", polymer);
    reaction.Execute();
    REQUIRE(tracker.species("p1") == 0);
    REQUIRE(tracker.species("ecolipol") == 0);
    REQUIRE(polymer->uncovered("p1") == 0);
    REQUIRE(prom->IsCovered());
  }
}

TEST_CASE("SpeciesTracker methods", "[SpeciesTracker]") {
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();

  SECTION("Increment species") {
    tracker.Increment("reactant1", 1);
    REQUIRE(tracker.species("reactant1") == 1);
    tracker.Increment("reactant2", 1);
    REQUIRE(tracker.species("reactant2") == 1);
    tracker.Increment("reactant1", 2);
    REQUIRE(tracker.species("reactant1") == 3);
  }

  SECTION("Add polymer") {
    Polymer::Ptr polymer;
    tracker.Add("promoter1", polymer);
    auto polymers = tracker.FindPolymers("promoter1");
    REQUIRE(std::find(polymers.begin(), polymers.end(), polymer) !=
            polymers.end());
    tracker.Add("promoter2", polymer);
    polymers = tracker.FindPolymers("promoter2");
    REQUIRE(std::find(polymers.begin(), polymers.end(), polymer) !=
            polymers.end());
  }
}

TEST_CASE("Simulation methods", "[Simulation]") {
  auto sim = Simulation();
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  tracker.Increment("reactant1", 1);

  SECTION("Register reaction") {
    auto reaction1 = std::make_shared<SpeciesReaction>(
        1.5, std::vector<std::string>{"reactant1"},
        std::vector<std::string>{"product1"});
    sim.RegisterReaction(reaction1);
    sim.InitPropensity();
    REQUIRE(sim.alpha_sum() == 1.5);
  }
}<commit_msg>completed Simulation unit tests<commit_after>#include <catch.hpp>

#include "simulation.hpp"

TEST_CASE("SpeciesReaction methods", "[Reaction]") {
  auto reaction = std::make_shared<SpeciesReaction>(
      1000, std::vector<std::string>{"reactant1", "reactant2"},
      std::vector<std::string>{"product1", "product2"});
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  tracker.Register(reaction);
  tracker.Increment("reactant1", 2);
  tracker.Increment("reactant2", 3);

  SECTION("Initialization and registration") {
    REQUIRE_THROWS(SpeciesReaction(
        1000, std::vector<std::string>{"reactant1", "reactant2", "reactant3"},
        std::vector<std::string>{"product1", "product2"}));
    // Make sure that maps have been set up appropriately
    auto reactions = tracker.FindReactions("reactant1");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("reactant2");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("product1");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
    reactions = tracker.FindReactions("product2");
    REQUIRE(std::find(reactions.begin(), reactions.end(), reaction) !=
            reactions.end());
  }

  SECTION("Propensity calculation") {
    REQUIRE((1000 * 2 * 3) / (double(6.0221409e+23) * double(8e-15)) ==
            reaction->CalculatePropensity());
  }

  SECTION("Execution") {
    reaction->Execute();
    REQUIRE(tracker.species("reactant1") == 1);
    REQUIRE(tracker.species("reactant2") == 2);
    REQUIRE(tracker.species("product1") == 1);
    REQUIRE(tracker.species("product1") == 1);
  }
}

TEST_CASE("Bind methods", "[Reaction]") {
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  // Set up a polymer
  std::vector<std::string> interactions = {"ecolipol"};
  Promoter::Ptr prom;
  Terminator::Ptr term;
  prom = std::make_shared<Promoter>("p1", 5, 15, interactions);
  std::map<std::string, double> efficiency;
  efficiency["ecolipol"] = 0.6;
  term = std::make_shared<Terminator>("t1", 50, 55, interactions, efficiency);

  std::vector<Element::Ptr> elements;
  elements.push_back(prom);
  elements.push_back(term);
  std::vector<std::string> mask_interactions = {"ecolipol"};
  Mask mask = Mask("test_mask", 50, 100, mask_interactions);

  auto polymer =
      std::make_shared<Polymer>("test_polymer", 1, 100, elements, mask);
  // Set up a polymerase
  auto polymerase = Polymerase("ecolipol", 10, 30);
  auto reaction = Bind(1000, "p1", polymerase);

  SECTION("Calculate propensity") {
    tracker.Increment("p1", 2);
    tracker.Increment("ecolipol", 3);
    REQUIRE((1000 * 2 * 3) / (double(6.0221409e+23) * double(8e-15)) ==
            reaction.CalculatePropensity());
  }

  SECTION("Execution") {
    tracker.Clear();
    tracker.Increment("p1", 1);
    tracker.Increment("ecolipol", 1);
    tracker.Add("p1", polymer);
    reaction.Execute();
    REQUIRE(tracker.species("p1") == 0);
    REQUIRE(tracker.species("ecolipol") == 0);
    REQUIRE(polymer->uncovered("p1") == 0);
    REQUIRE(prom->IsCovered());
  }
}

TEST_CASE("SpeciesTracker methods", "[SpeciesTracker]") {
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();

  SECTION("Increment species") {
    tracker.Increment("reactant1", 1);
    REQUIRE(tracker.species("reactant1") == 1);
    tracker.Increment("reactant2", 1);
    REQUIRE(tracker.species("reactant2") == 1);
    tracker.Increment("reactant1", 2);
    REQUIRE(tracker.species("reactant1") == 3);
  }

  SECTION("Add polymer") {
    Polymer::Ptr polymer;
    tracker.Add("promoter1", polymer);
    auto polymers = tracker.FindPolymers("promoter1");
    REQUIRE(std::find(polymers.begin(), polymers.end(), polymer) !=
            polymers.end());
    tracker.Add("promoter2", polymer);
    polymers = tracker.FindPolymers("promoter2");
    REQUIRE(std::find(polymers.begin(), polymers.end(), polymer) !=
            polymers.end());
  }
}

TEST_CASE("Simulation methods", "[Simulation]") {
  auto sim = Simulation();
  auto &tracker = SpeciesTracker::Instance();
  tracker.Clear();
  tracker.Increment("reactant1", 1);

  SECTION("Register reaction") {
    auto reaction1 = std::make_shared<SpeciesReaction>(
        1.5, std::vector<std::string>{"reactant1"},
        std::vector<std::string>{"product1"});
    sim.RegisterReaction(reaction1);
    sim.InitPropensity();
    REQUIRE(sim.alpha_sum() == 1.5);
    auto reaction2 = std::make_shared<SpeciesReaction>(
        1.5, std::vector<std::string>{"reactant1"},
        std::vector<std::string>{"product1"});
    sim.RegisterReaction(reaction2);
    sim.InitPropensity();
    REQUIRE(sim.alpha_sum() == 3);
  }

  SECTION("Register polymer and execute") {
    tracker.Clear();
    // Set up a polymer
    std::vector<std::string> interactions = {"ecolipol"};
    Promoter::Ptr prom;
    Terminator::Ptr term;
    prom = std::make_shared<Promoter>("p1", 5, 15, interactions);
    std::map<std::string, double> efficiency;
    efficiency["ecolipol"] = 0.6;
    term = std::make_shared<Terminator>("t1", 50, 55, interactions, efficiency);

    std::vector<Element::Ptr> elements;
    elements.push_back(prom);
    elements.push_back(term);
    std::vector<std::string> mask_interactions = {"ecolipol"};
    Mask mask = Mask("test_mask", 50, 100, mask_interactions);

    auto polymer =
        std::make_shared<Polymer>("test_polymer", 1, 100, elements, mask);

    sim.RegisterPolymer(polymer);
    REQUIRE(tracker.FindPolymers("p1")[0] == polymer);
    // bind polymerase and make sure alpha list is updated appropriately
    auto polymerase = Polymerase("ecolipol", 10, 30);
    // Wire up reaction with tracker (TODO: clean this up)
    tracker.Increment("ecolipol", 2);
    tracker.Increment("p1", 1);
    auto reaction = std::make_shared<Bind>(1000, "p1", polymerase);
    tracker.Add("p1", reaction);
    tracker.Add("ecolipol", reaction);
    tracker.Add("p1", polymer);
    sim.RegisterReaction(reaction);
    sim.InitPropensity();
    sim.Execute();
    REQUIRE(sim.alpha_sum() == 30);
    sim.Execute();
    REQUIRE(sim.alpha_sum() == 30);
    for (int i = 0; i < 20; i++) {
      sim.Execute();
    }
    // Alpha_sum should be slightly greather than 30 now that promoter is
    // re-exposed
    REQUIRE(sim.alpha_sum() > 30);
  }
}
{'fraction_non_alphanumeric': 0.1781864299302473, 'fraction_numerical': 0.029894012138780686, 'mean_word_length': 4.317919075144508, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3804136', 'n_tokens_mistral': 4008, 'n_tokens_neox': 3595, 'n_words': 633}