Browse Source

Merge branch 'division' into 'master'

Division

See merge request fdai8031/cstools101!9
master
fdai7968 11 months ago
parent
commit
0e14035c7d
  1. 0
      src/division/.gitkeep
  2. 10
      src/division/division.c
  3. 7
      src/division/division.h
  4. 0
      test/division/.gitkeep
  5. 10
      test/division/test_division.c

0
src/division/.gitkeep

10
src/division/division.c

@ -0,0 +1,10 @@
#include "division.h"
float divide(float dividend, float divisor) {
if (divisor == 0) {
return 0; // Fehlerbehandlung: Division durch Null ist nicht definiert, daher geben wir einfach 0 zurück.
}
if (dividend == 0) return 0;
else if(dividend==divisor) return 1;
else return dividend / divisor;
}

7
src/division/division.h

@ -0,0 +1,7 @@
#ifndef division_H
#define division_H
int divide(float dividend, float divisor);
#endif

0
test/division/.gitkeep

10
test/division/test_division.c

@ -0,0 +1,10 @@
#include "unity.h"
#include "division.h"
void setUp(void){}
void tearDown(void){}
void test_division() {
TEST_ASSERT_EQUAL_FLOAT(2.0f, divide(6.0f, 3.0f));
TEST_ASSERT_EQUAL_FLOAT(-2.0f, divide(6.0f, -3.0f));
TEST_ASSERT_EQUAL_FLOAT(0.0f, divide(0.0f, 5.0f));
TEST_ASSERT_EQUAL_FLOAT(0.0f, divide(5.0f, 0.0f)); // Test für Division durch Null
}
Loading…
Cancel
Save