Skip to content

Commit 08a77a9

Browse files
shingarovjanvrany
authored andcommitted
[Squiggol] Add some fun tests
1 parent f34e169 commit 08a77a9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/PreSmalltalks-Tests/FoldlIsInjectTest.class.st

+14
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ FoldlIsInjectTest >> test4 [
3838
FoldlIsInjectTest >> test5 [
3939
self assert: ({1 . 2 . 3} inject: 4 into: [ :x :y | 2*x + y ]) equals: 43
4040
]
41+
42+
{ #category : #tests }
43+
FoldlIsInjectTest >> testFactorial0 [
44+
self
45+
assert: 0 factorialHylomorphically
46+
equals: 1
47+
]
48+
49+
{ #category : #tests }
50+
FoldlIsInjectTest >> testFactorial5 [
51+
self
52+
assert: 5 factorialHylomorphically
53+
equals: 120
54+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Extension { #name : #Integer }
2+
3+
{ #category : #'*PreSmalltalks-Tests' }
4+
Integer >> factorialHylomorphically [
5+
self < 0 ifTrue: [self error: 'Not valid for negative integers'].
6+
^(1 to: self) "anamorphism: unfold scalar to an inductive datatype"
7+
inject: 1 into: #* "catamorphism: fold inductive datatype to scalar"
8+
]

0 commit comments

Comments
 (0)