Today I started to write a class in Scala to represent a group (in the mathematical sense).
To test closure, i.e.:
the code I wrote is:
def closure( ): Boolean =
elements.forall(
el => elements.forall(
el2 => elements.exists(
el2.*(el, this).name == _.name ) ) )
'elements' is the list of all group elements and and each element has a different 'name'.
The following piece of code is the product of two elements.
el2.*(el, this)
the * operator is defined as follows:
def *( b : groupElement ,group: genericGroup ) : groupElement
the code is not optimized, but it is amazing how, in this language,
we can write a test like this in a way so simple!
we can write a test like this in a way so simple!
this is only a snippet of the entire code...
I hope to post the complete code soon
1 commento:
nice but not so clear
Posta un commento