Browse Source

Merge branch 'Fakultaet' into 'master'

Fakultaet

See merge request fdai7848/Linkes-Twix!7
master
fdai7720 11 months ago
parent
commit
f1e820ce54
  1. 25
      src/fakultaet.c
  2. 13
      src/fakultaet.h
  3. 33
      test/test_fakultaet.c

25
src/fakultaet.c

@ -0,0 +1,25 @@
#include "fakultaet.h"
int berechneFakultaetInt(int zahl) {
if (zahl == 0 || zahl == 1) {
return 1;
} else {
int fakultaet = 1;
for (int i = 2; i <= zahl; ++i) {
fakultaet *= i;
}
return fakultaet;
}
}
int berechneFakultaetDouble(double zahl) {
if (zahl == 0 || zahl == 1) {
return 1;
} else {
double fakultaet = 1;
for (double i = 2; i <= zahl; ++i) {
fakultaet *= i;
}
return fakultaet;
}
}

13
src/fakultaet.h

@ -0,0 +1,13 @@
//
// Created by Justin Trausch on 06.02.2024.
//
#ifndef LINKES_TWIX_FAKULTAET_H
#define LINKES_TWIX_FAKULTAET_H
int fakultaetInt(int a, int b);
double fakultaetDouble(double a, double b);
#endif //LINKES_TWIX_FAKULTAET_H

33
test/test_fakultaet.c

@ -0,0 +1,33 @@
#ifdef TEST
#include "unity.h"
#include "fakultaet.h"
#include "fakultaet.c"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_fakultaet_1(void)
{
int result, expected = 24;
result = berechneFakultaetInt(4);
TEST_ASSERT_EQUAL_INT(expected, result);
}
void test_fakultaet_2(void)
{
double result, expected = 24.0;
result = berechneFakultaetInt(4.0);
TEST_ASSERT_EQUAL_DOUBLE(expected, result);
}
#endif //TEST
Loading…
Cancel
Save