Browse Source

Merge branch 'Division' into 'master'

Division

See merge request fdai7848/Linkes-Twix!6
master
fdai7720 11 months ago
parent
commit
8b831bde19
  1. 13
      src/division.h
  2. 26
      src/divsion.c
  3. 61
      test/test_division.c

13
src/division.h

@ -0,0 +1,13 @@
//
// Created by Justin Trausch on 06.02.2024.
//
#ifndef LINKES_TWIX_DIVISION_H
#define LINKES_TWIX_DIVISION_H
int divisionInt(int a, int b);
double divisionDouble(double a, double b);
int divisionByTwo(int a, int b);
#endif //LINKES_TWIX_DIVISION_H

26
src/divsion.c

@ -0,0 +1,26 @@
#include "division.h"
int divisionInt(int a, int b) {
if (b != 0) {
return a / b;
}
else {
return 0;
}
}
double divisionDouble(double a, double b) {
if (b != 0) {
return a / b;
}
else {
return 0;
}
}
int divisionByTwo(int a, int b) {
if (b == 0){
return a;
}
return a >> b;
}

61
test/test_division.c

@ -0,0 +1,61 @@
#ifdef TEST
#include "unity.h"
#include "division.h"
#include "divsion.c"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_division_1(void)
{
int result, expected = 5;
result = divisionInt(10,2);
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_division_1_durch_0(void)
{
int result, expected = 0;
result = divisionInt(10,0);
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_division_2(void)
{
double result, expected = 5.0;
result = divisionDouble(10.0,2.0);
TEST_ASSERT_EQUAL_DOUBLE(expected, result);
}
void test_bitshift_druch_0(void)
{
int result, expected = 16;
result = divisionByTwo(16,0);
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_division_3(void)
{
int result, expected = 4;
result = divisionByTwo(16,2);
TEST_ASSERT_EQUAL_INT(expected, result);
}
#endif // TEST
Loading…
Cancel
Save