Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feature/implement-python-binding-for-core-module' of gi…
Browse files Browse the repository at this point in the history
…thub.com:MGTheTrain/cpp-sample-bindings into feature/implement-python-binding-for-core-module
  • Loading branch information
MGTheTrain committed Apr 15, 2024
2 parents 450f708 + bda15a7 commit 8a72c79
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 57 deletions.
Empty file modified devops/scripts/bash/compile_source_code.sh
100644 → 100755
Empty file.
Empty file modified devops/scripts/bash/format_and_lint.sh
100644 → 100755
Empty file.
12 changes: 6 additions & 6 deletions modules/core/include/math-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#define M_PI 3.141

extern "C" {
int32_t add(int32_t a, int32_t b);
int32_t subtract(int32_t a, int32_t b);
int32_t multiply(int32_t a, int32_t b);
float divide(float a, float b);
float getCircleArea(float radius);
float getCircleCircumference(float radius);
int32_t add(int32_t a, int32_t b);
int32_t subtract(int32_t a, int32_t b);
int32_t multiply(int32_t a, int32_t b);
float divide(float a, float b);
float getCircleArea(float radius);
float getCircleCircumference(float radius);
}
25 changes: 6 additions & 19 deletions modules/core/src/math-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,29 @@

#include <math-utils.h>


/**
* @brief Adds two integers.
* @param a The first integer.
* @param b The second integer.
* @return The sum of a and b.
*/
int32_t add(int32_t a, int32_t b) {
return a + b;
}
int32_t add(int32_t a, int32_t b) { return a + b; }

/**
* @brief Subtracts one integer from another.
* @param a The integer to subtract from.
* @param b The integer to subtract.
* @return The result of subtracting b from a.
*/
int32_t subtract(int32_t a, int32_t b) {
return a - b;
}
int32_t subtract(int32_t a, int32_t b) { return a - b; }

/**
* @brief Multiplies two integers.
* @param a The first integer.
* @param b The second integer.
* @return The product of a and b.
*/
int32_t multiply(int32_t a, int32_t b) {
return a * b;
}
int32_t multiply(int32_t a, int32_t b) { return a * b; }

/**
* @brief Divides one float by another.
Expand All @@ -60,24 +53,18 @@ int32_t multiply(int32_t a, int32_t b) {
* @return The result of dividing a by b.
* @throw Division by zero error if b is zero.
*/
float divide(float a, float b) {
return a / b;
}
float divide(float a, float b) { return a / b; }

/**
* @brief Calculates the area of the circle.
* @param radius The radius of the circle.
* @return The area of the circle.
*/
float getCircleArea(float radius) {
return M_PI * radius * radius;
}
float getCircleArea(float radius) { return M_PI * radius * radius; }

/**
* @brief Calculates the circumference of the circle.
* @param radius The radius of the circle
* @return The circumference of the circle.
*/
float getCircleCircumference(float radius) {
return 2 * M_PI * radius;
}
float getCircleCircumference(float radius) { return 2 * M_PI * radius; }
66 changes: 34 additions & 32 deletions modules/core/test/math-utils-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,77 +20,79 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#ifdef MGTT_CORE_TEST
#ifdef MGTT_CORE_TEST

#include <gtest/gtest.h>
#include <math-utils.h>

// Test fixture for MathOperations tests
class MathOperationsTest : public ::testing::Test {
protected:
void SetUp() override {}
void TearDown() override {}
protected:
void SetUp() override {}
void TearDown() override {}
};

// Test case for MathOperations::add method
TEST_F(MathOperationsTest, AddTest) {
int a = 5;
int b = 3;
int a = 5;
int b = 3;

int result = add(a, b);
EXPECT_EQ(result, 8);
int result = add(a, b);
EXPECT_EQ(result, 8);
}

// Test case for MathOperations::subtract method
TEST_F(MathOperationsTest, SubtractTest) {
int a = 5;
int b = 3;
int a = 5;
int b = 3;

int result = subtract(a, b);
EXPECT_EQ(result, 2); // Expect the result to be 2
int result = subtract(a, b);
EXPECT_EQ(result, 2); // Expect the result to be 2
}

// Test case for MathOperations::multiply method
TEST_F(MathOperationsTest, MultiplyTest) {
int a = 5;
int b = 3;
int a = 5;
int b = 3;

int result = multiply(a, b);
EXPECT_EQ(result, 15); // Expect the result to be 15
int result = multiply(a, b);
EXPECT_EQ(result, 15); // Expect the result to be 15
}

// Test case for MathOperations::divide method
TEST_F(MathOperationsTest, DivideTest) {
float a = 10.0f;
float b = 2.0f;
float a = 10.0f;
float b = 2.0f;

float result = divide(a, b);
EXPECT_FLOAT_EQ(result, 5.0f); // Expect the result to be 5.0
float result = divide(a, b);
EXPECT_FLOAT_EQ(result, 5.0f); // Expect the result to be 5.0
}

// Test fixture for Circle tests
class CircleTest : public ::testing::Test {
protected:
void SetUp() override {}
void TearDown() override {}
protected:
void SetUp() override {}
void TearDown() override {}
};

// Test case for Circle::getArea method
TEST_F(CircleTest, GetAreaTest) {
float radius = 5.0f;
float expectedArea = M_PI * radius * radius;
float radius = 5.0f;
float expectedArea = M_PI * radius * radius;

float area = getCircleArea(radius);
EXPECT_FLOAT_EQ(area, expectedArea); // Expect the area to be pi * r^2
float area = getCircleArea(radius);
EXPECT_FLOAT_EQ(area, expectedArea); // Expect the area to be pi * r^2
}

// Test case for Circle::getCircumference method
TEST_F(CircleTest, GetCircumferenceTest) {
float radius = 5.0f;
float expectedCircumference = 2 * M_PI * radius;
float radius = 5.0f;
float expectedCircumference = 2 * M_PI * radius;

float circumference = getCircleCircumference(radius);
EXPECT_FLOAT_EQ(circumference, expectedCircumference); // Expect the circumference to be 2 * pi * r
float circumference = getCircleCircumference(radius);
EXPECT_FLOAT_EQ(
circumference,
expectedCircumference); // Expect the circumference to be 2 * pi * r
}

#endif // End of MGTT_CORE_TEST
#endif // End of MGTT_CORE_TEST

0 comments on commit 8a72c79

Please sign in to comment.