Skip to content

Commit 264d56c

Browse files
committed
Wrote more tests for mathematical fucntions
1 parent 65367e8 commit 264d56c

File tree

2 files changed

+109
-27
lines changed

2 files changed

+109
-27
lines changed

src/DataFrame-Tests/DataSeriesTest.class.st

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -609,18 +609,6 @@ DataSeriesTest >> testCopyChangeDoesNotAffectOriginal [
609609

610610
]
611611

612-
{ #category : #tests }
613-
DataSeriesTest >> testCos [
614-
615-
| a b pi |
616-
617-
pi := Float pi.
618-
a := { 0 . pi . pi/2 . pi/4 . pi/3 } asDataSeries.
619-
b := { 1.0 . -1.0 . 0.0 . 1/2 sqrt . 0.5 } asDataSeries.
620-
621-
self assert: a cos closeTo: b.
622-
]
623-
624612
{ #category : #tests }
625613
DataSeriesTest >> testCreateDataSeriesAsDataSeries [
626614

@@ -952,13 +940,74 @@ DataSeriesTest >> testLast [
952940
]
953941

954942
{ #category : #tests }
955-
DataSeriesTest >> testNinth [
943+
DataSeriesTest >> testMathAbs [
956944

957-
self assert: series ninth equals: 15.
945+
| a b |
946+
947+
a := { 1 . -2 . 3 . -4 } asDataSeries.
948+
b := { 1 . 2 . 3 . 4 } asDataSeries.
949+
950+
self assert: a abs closeTo: b.
958951
]
959952

960953
{ #category : #tests }
961-
DataSeriesTest >> testPowerScalar [
954+
DataSeriesTest >> testMathCos [
955+
956+
| a b pi |
957+
958+
pi := Float pi.
959+
a := { 0 . pi . pi/2 . pi/4 . pi/3 } asDataSeries.
960+
b := { 1.0 . -1.0 . 0.0 . 1/2 sqrt . 0.5 } asDataSeries.
961+
962+
self assert: a cos closeTo: b.
963+
]
964+
965+
{ #category : #tests }
966+
DataSeriesTest >> testMathExp [
967+
968+
| a b |
969+
970+
a := { 1 . 2 . 3 . 4 } asDataSeries.
971+
b := { 2.71828 . 7.38906 . 20.08554 . 54.59815 } asDataSeries.
972+
973+
self assert: a exp closeTo: b.
974+
]
975+
976+
{ #category : #tests }
977+
DataSeriesTest >> testMathLn [
978+
979+
| a b |
980+
981+
a := { 1 . 2 . 3 . 4 } asDataSeries.
982+
b := { 0 . 0.69315 . 1.09861 . 1.38629 } asDataSeries.
983+
984+
self assert: a ln closeTo: b.
985+
]
986+
987+
{ #category : #tests }
988+
DataSeriesTest >> testMathLog [
989+
990+
| a b |
991+
992+
a := { 1 . 2 . 3 . 4 } asDataSeries.
993+
b := { 0.0 . 0.30103 . 0.47712 . 0.60205 } asDataSeries.
994+
995+
self assert: a log closeTo: b.
996+
]
997+
998+
{ #category : #tests }
999+
DataSeriesTest >> testMathLog2 [
1000+
1001+
| a b |
1002+
1003+
a := { 1 . 2 . 3 . 4 } asDataSeries.
1004+
b := { 0 . 1 . 1.58496 . 2 } asDataSeries.
1005+
1006+
self assert: (a log: 2) closeTo: b.
1007+
]
1008+
1009+
{ #category : #tests }
1010+
DataSeriesTest >> testMathPowerScalar [
9621011

9631012
| a b |
9641013

@@ -968,6 +1017,46 @@ DataSeriesTest >> testPowerScalar [
9681017
self assert: a ** 2 equals: b.
9691018
]
9701019

1020+
{ #category : #tests }
1021+
DataSeriesTest >> testMathSin [
1022+
1023+
| a b pi |
1024+
1025+
pi := Float pi.
1026+
a := { 0 . pi . pi/2 . pi/4 . pi/6 } asDataSeries.
1027+
b := { 0.0 . 0.0 . 1.0 . 1/2 sqrt . 0.5 } asDataSeries.
1028+
1029+
self assert: a sin closeTo: b.
1030+
]
1031+
1032+
{ #category : #tests }
1033+
DataSeriesTest >> testMathSqrt [
1034+
1035+
| a b |
1036+
1037+
a := { 1 . 2 . 3 . 4 } asDataSeries.
1038+
b := { 1 . 1.41421 . 1.73205 . 2 } asDataSeries.
1039+
1040+
self assert: a sqrt closeTo: b.
1041+
]
1042+
1043+
{ #category : #tests }
1044+
DataSeriesTest >> testMathTan [
1045+
1046+
| a b |
1047+
1048+
a := { 1 . 2 . 3 . 4 } asDataSeries.
1049+
b := { 1.55741 . -2.18504 . -0.14255 . 1.15782 } asDataSeries.
1050+
1051+
self assert: a tan closeTo: b.
1052+
]
1053+
1054+
{ #category : #tests }
1055+
DataSeriesTest >> testNinth [
1056+
1057+
self assert: series ninth equals: 15.
1058+
]
1059+
9711060
{ #category : #tests }
9721061
DataSeriesTest >> testReject [
9731062

@@ -1038,18 +1127,6 @@ DataSeriesTest >> testSeventh [
10381127
self assert: series seventh equals: 8.
10391128
]
10401129

1041-
{ #category : #tests }
1042-
DataSeriesTest >> testSin [
1043-
1044-
| a b pi |
1045-
1046-
pi := Float pi.
1047-
a := { 0 . pi . pi/2 . pi/4 . pi/6 } asDataSeries.
1048-
b := { 0.0 . 0.0 . 1.0 . 1/2 sqrt . 0.5 } asDataSeries.
1049-
1050-
self assert: a sin closeTo: b.
1051-
]
1052-
10531130
{ #category : #tests }
10541131
DataSeriesTest >> testSixth [
10551132

src/DataFrame/DataSeries.class.st

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ DataSeries >> last [
291291
^ self atIndex: self size
292292
]
293293

294+
{ #category : #'math functions' }
295+
DataSeries >> log: base [
296+
^ self collect: [ :each | each log: base ]
297+
]
298+
294299
{ #category : #accessing }
295300
DataSeries >> mode [
296301
| valueCounts maxCount |

0 commit comments

Comments
 (0)