Coverage for src/test_main.py: 100%

# Coverage for src/test_main.py : 100%

## 7 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 import pytest

2 import coverage

3 from FADiff import FADiff

4

5 class TestClass:

6 def test_test(self):

7 x = 3

8 assert x == 3

9# def test_neg(self):

10# x = -FADiff(3, 1)

11# assert x.val == -3

12# assert x.der == -1

13

14# def test_add(self):

15# x = FADiff(3, 1) + 5

16# assert x.val == 8

17# assert x.der == 1

18

19# y = FADiff(3, 0) + FADiff(5, 0)

20# assert y.val == 8

21# assert y.der == 0

22

23# def test_radd(self):

24# x = 5 + FADiff(3, 1)

25# assert x.val == 8

26# assert x.der == 1

27

28# def test_sub(self):

29# x = FADiff(3, 1) - 5

30# assert x.val == -2

31# assert x.der == 1

32

33# y = FADiff(3, 1) - FADiff(2, 1)

34# assert y.val == 1

35# assert x.der == 1

36

37# def test_rsub(self):

38# x = 3 - FADiff(3, 1)

39# assert x.val == 0

40# assert x.der == 1

41

42# def test_mul(self):

43# x = FADiff(3, 1) * 3

44# assert x.val == 9

45# assert x.der == 3

46# y = FADiff(3, 1) * FADiff(4, 1)

47# assert y.val == 12

48# assert y.der == 7

49

50# def test_rmul(self):

51# x = 3 * FADiff(3, 1)

52# assert x.val == 9

53# assert x.der == 3

54

55# def test_div(self):

56# x = FADiff(3, 1) / 3

57# assert x.val == 1

58# assert x.der == pytest.approx(0.3333333333333333)

59

60# y = FADiff(3, 1) / FADiff(4, 1)

61# assert y.val == pytest.approx(0.75)

62# assert y.der == pytest.approx(0.0625)

63

64# def test_rdiv(self):

65# x = 3 / FADiff(3, 1)

66# assert x.val == 1

67# assert x.der == pytest.approx(-0.3333333333333333)

68

69# def test_pow(self):

70# x = FADiff(3, 1) ** 2

71# assert x.val == 9

72# assert x.der == 6

73

74# y = FADiff(3, 1) ** FADiff(5, 1)

75# assert y.val == 243

76# assert y.der == 405

77

78# def test_rpow(self):

79# x = 2 ** FADiff(3, 1)

80# assert x.val == 8

81# assert x.der == pytest.approx(5.54517744)

82

83# def test_exp(self):

84# x = FADiff.exp(FADiff(3, 1))

85# assert x.val == pytest.approx(20.085536923187668)

86# assert x.der == pytest.approx(20.085536923187668)

87

88# def test_cos(self):

89# x = FADiff.cos(FADiff(3, 1))

90# assert x.val == pytest.approx(-0.9899924966004454)

91# assert x.der == pytest.approx(-0.1411200080598672)

92

93# def test_sin(self):

94# x = FADiff.sin(FADiff(3, 1))

95# assert x.val == pytest.approx(0.1411200080598672)

96# assert x.der == pytest.approx(-0.9899924966004454)

97

98# def test_tan(self):

99# x = FADiff.tan(FADiff(3, 1))

100# assert x.val == pytest.approx(-0.1425465430742778)

101# assert x.der == pytest.approx(1.020319516942427)