Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / bench_netsim.nit
index d4a9122..6531814 100644 (file)
@@ -19,7 +19,7 @@ class Node
        do
                return _name
        end
-       var _name: String = "noname"
+       var name: String = "noname"
 end
 
 class WakeUpNode
@@ -31,17 +31,16 @@ class WakeUpNode
        do
                _scheduler.add_event(self, d)
        end
-       var _scheduler: Scheduler
+       var scheduler: Scheduler is noinit
 end
 
 class NodeSource
        super Node
-       var _nexts: nullable ArraySet[NodeSink] = null
+       var nexts: nullable ArraySet[NodeSink] = null
        fun attach(n: NodeSink)
        # Add the sink `n' the the connected nodes
        # Do nothing if `n' is already connected
        do
-               assert n != null
                # Create the collection if needed
                if _nexts == null then
                        _nexts = new ArraySet[NodeSink]
@@ -53,7 +52,6 @@ class NodeSource
        # Remove the sink `n' from the connected nodes
        # Do nothing if `n' is not connected
        do
-               assert n != null
                _nexts.remove(n)
        end
 
@@ -78,8 +76,8 @@ end
 #
 
 class Scheduler
-       var _time_list: Array[Couple[Int, WakeUpNode]] = new Array[Couple[Int, WakeUpNode]]
-       var _time: Int = 0 # What time is it ?
+       var time_list: Array[Couple[Int, WakeUpNode]] = new Array[Couple[Int, WakeUpNode]]
+       var time: Int = 0 # What time is it ?
        fun add_event(n: WakeUpNode, d: Int)
        # The node `n' whant to be weaked up in `d' time units
        do
@@ -109,7 +107,7 @@ class Scheduler
 
        fun run_for(time_limit: Int)
        do
-               while true do
+               loop
                        var node = next_event 
                        if _time > time_limit then
                                print("Time limit.")
@@ -138,7 +136,7 @@ class BeepSource
                send
                wake_up_in(_delay)
        end
-       var _delay: Int
+       var delay: Int
        fun start
        do
                wake_up_in(_delay)
@@ -154,10 +152,10 @@ end
 
 class CountSink
        super NodeSink
-       readable var _count: Int = 0
+       var count: Int = 0
        redef fun recieve(n: NodeSource)
        do
-               _count = _count + 1
+               count = count + 1
        end
 end
 
@@ -173,7 +171,7 @@ end
 class NodeAlternate
        super NodeSink
        super NodeSource
-       var _last: nullable NodeSource
+       var last: nullable NodeSource
        redef fun recieve(n: NodeSource)
        do
                if n != _last then
@@ -191,15 +189,15 @@ end
 class NodeEat
        super CountSink
        super NodeSource
-       var _limit: Int
+       var limit: Int
        redef fun recieve(n: NodeSource)
        do
-               var c = _count + 1
+               var c = count + 1
                if c >= _limit then
-                       _count = 0
+                       count = 0
                        send
                else
-                       _count = c
+                       count = c
                end
        end
 
@@ -214,7 +212,7 @@ class NodeDelay
        super NodeSource
        super NodeSink
        super WakeUpNode
-       var _delay: Int
+       var delay: Int
        redef fun recieve(n: NodeSource)
        do
                wake_up_in(_delay)
@@ -269,11 +267,11 @@ e1.attach(a1)
 b1.start
 b2.start
 
-var nb = 100000
+var nb = 10
 if not args.is_empty then
        nb = args.first.to_i
 end
 
-s.run_for(nb)
+s.run_for(1 << nb)
 print(c1.count)