summaryrefslogtreecommitdiff
path: root/lib/Evolving/test/test1.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Evolving/test/test1.coffee')
-rw-r--r--lib/Evolving/test/test1.coffee59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/Evolving/test/test1.coffee b/lib/Evolving/test/test1.coffee
new file mode 100644
index 0000000..e59cb20
--- /dev/null
+++ b/lib/Evolving/test/test1.coffee
@@ -0,0 +1,59 @@
+{ Evolving } = require '../evolving'
+
+# Firstly define four classes
+
+# define a mewing kitten
+Kitten = Evolving::evolve ->
+ @sound = "~mew~"
+ @
+
+# evolve them into a grow cat, who can "meow"
+Cat = Kitten::evolve ->
+ @sound = "~meow~"
+ @
+
+# define a person with a name
+Person = Evolving::evolve ->
+ @setName = (@name)-> @
+ @intro = -> "Hi, I'm #{ @name }. #{ @sound ? "" }"
+ @
+
+# evolve them into a professor in certain subjects
+Professor = Person::evolve ->
+ # It is assumed that every professors knows rudiments of epistemology!
+ @subjects = [ "Epistemology" ]
+ @addSubject = (s)-> @subjects = @subjects.concat([ s ]); @
+ @randomSubject = -> @subjects.sort(-> Math.random() - 0.5)[0]
+ personIntro = @intro
+ @intro = ->
+ personIntro.call(@) +
+ " Today, we are going to learn about " +
+ @randomSubject()
+ @
+
+# Describe the evolution of an Odd Professor, by combining Professor and Cat and adding a training in Sociology
+OddProfessorEvolution = ->
+ Professor.evolution.call @
+ Cat.evolution.call @
+ @addSubject "Sociology"
+
+# a kitten is born
+kitten = new Kitten()
+
+# name the kitten Alice, making them also a person in the process
+alice = (new ( kitten.evolve( Person.evolution ) )).setName('Alice')
+
+# evolve Alice into an odd professor
+aliceTheCatProfessor = new ( alice.evolve( OddProfessorEvolution ) )
+
+console.log """
+
+Alice in her own words:
+
+ #{ alice.intro() }
+
+Alice, after the evolution, introducing herself:
+
+ #{ aliceTheCatProfessor.intro() }
+
+"""