Skip to content

Commit

Permalink
Implemented variables and add googletest as submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Apr 30, 2024
1 parent 1680712 commit dcc845f
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "test/lib/googletest"]
path = test/lib/googletest
url = [email protected]:google/googletest.git
1 change: 1 addition & 0 deletions src/random_events/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ add_library(random_events_lib interval.cpp
include/set.h
set.cpp
variable.cpp
include/product_algebra.h
)
target_include_directories(random_events_lib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
17 changes: 17 additions & 0 deletions src/random_events/include/product_algebra.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "sigma_algebra.h"


class Event; // Forward declaration

class SimpleEvent : public SimpleSetWrapper<Event, SimpleEvent, std::tuple<int>> {

};

/**
* Class that represents the product algebra.
*/
class Event : public CompositeSetWrapper<Event, SimpleEvent, std::tuple<int>> {

};
24 changes: 24 additions & 0 deletions src/random_events/include/variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

#include "sigma_algebra.h"
#include "interval.h"
#include "set.h"
#include <string>
#include <utility>


/**
* Template class for variables.
*/
template<typename T_Variable, typename T_Domain>
class Variable {
public:
Expand All @@ -24,6 +29,25 @@ class Variable {

};


class Symbolic: public Variable<Symbolic, Set>{
public:
explicit Symbolic(std::string name, Set domain): Variable<Symbolic, Set>(std::move(name), std::move(domain)){};
};

class Integer: public Variable<Integer, Interval>{
public:

[[maybe_unused]] const Interval domain = reals();

explicit Integer(std::string name) : Variable(name, reals()) {
Variable<Integer, Interval>::name = std::move(name);
};
};

/**
* Class that represents a continuous variable.
*/
class Continuous: public Variable<Continuous, Interval>{
public:

Expand Down
14 changes: 11 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
project(GoogleTests)

add_subdirectory(lib)

include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

add_subdirectory(test_interval)
# adding the Google_Tests_run target
add_executable(RunUnitTest test_interval.cpp
test_set.cpp
test_variable.cpp)

include_directories(${SRC_DIR}/random_events/include)

# linking Google_Tests_run with random_events_lib which will be tested
target_link_libraries(RunUnitTest random_events_lib)

target_link_libraries(RunUnitTest gtest gtest_main)
1 change: 1 addition & 0 deletions test/lib/googletest
Submodule googletest added at d83fee
File renamed without changes.
11 changes: 0 additions & 11 deletions test/test_interval/CMakeLists.txt

This file was deleted.

9 changes: 0 additions & 9 deletions test/test_interval/test_variable.cpp

This file was deleted.

File renamed without changes.
22 changes: 22 additions & 0 deletions test/test_variable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "gtest/gtest.h"
#include "interval.h"
#include "variable.h"
#include "set.h"

TEST(Variable, Continuous) {
Continuous continuous("x");
EXPECT_EQ(continuous.name, "x");
EXPECT_EQ(continuous.domain, reals());
}

TEST(Variable, Symbolic) {
auto variable = Symbolic("x", Set({"a", "b", "c"}));
EXPECT_EQ(variable.name, "x");
EXPECT_EQ(variable.domain, Set({"a", "b", "c"}));
}

TEST(Variable, Integer) {
auto variable = Integer("x");
EXPECT_EQ(variable.name, "x");
EXPECT_EQ(variable.domain, reals());
}

0 comments on commit dcc845f

Please sign in to comment.