summaryrefslogtreecommitdiffstats
path: root/spec/spin_spec.rb
blob: 7e171a5a53b1b7cac3d4208ac8984a5c195f7acd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#

require 'spec_helper'
#
describe EvenDoors::Spin do
    #
    before(:each) do
        EvenDoors::Spin.clear!
    end
    #
    class MyP < EvenDoors::Particle; end
    #
    it "Particles pool" do
        p0 = EvenDoors::Spin.require_p EvenDoors::Particle
        p1 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p0===p1).should be_false
        EvenDoors::Spin.release_p p0
        p2 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p0===p2).should be_true
    end
    #
    it "different Particles classes in pool" do
        p0 = EvenDoors::Spin.require_p EvenDoors::Particle
        p1 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p0===p1).should be_false
        EvenDoors::Spin.release_p p0
        p2 = EvenDoors::Spin.require_p MyP
        p3 = EvenDoors::Spin.require_p MyP
        (p2===p3).should be_false
        EvenDoors::Spin.release_p p2
        p4 = EvenDoors::Spin.require_p MyP
        (p2===p4).should be_true
    end
    #
    it "release of merged particles" do
        p0 = EvenDoors::Spin.require_p EvenDoors::Particle
        p1 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p0===p1).should be_false
        p0.merge! p1
        EvenDoors::Spin.release_p p0
        p2 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p2===p0).should be_true
        p3 = EvenDoors::Spin.require_p EvenDoors::Particle
        (p3===p1).should be_true
    end
    #
    it "send_p send_sys_p spin!" do
        f = Fake.new
        p0 = EvenDoors::Spin.require_p EvenDoors::Particle
        p0.dst_routed!  f
        p1 = EvenDoors::Spin.require_p EvenDoors::Particle
        p1.dst_routed!  f
        EvenDoors::Spin.send_p p0
        EvenDoors::Spin.send_sys_p p1
        EvenDoors::Spin.run = true
        EvenDoors::Spin.spin!
        f.p.should be p0
        f.sp.should be p1
    end
    #
    it "option debug" do
        EvenDoors::Spin.debug_routing.should be false
        EvenDoors::Spin.debug_errors.should be false
        spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true, :debug_errors=>true
        EvenDoors::Spin.debug_routing.should be true
        EvenDoors::Spin.debug_errors.should be true
    end
    #
    it "only 1 Spin instance" do
        spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true
        lambda { EvenDoors::Spin.new('dom1') }.should raise_error(EvenDoors::Exception)
    end
    #
    it "spin->json->spin" do
        spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true
        r0 = EvenDoors::Room.new 'r0', spin
        r1 = EvenDoors::Room.new 'r1', r0
        r2 = EvenDoors::Room.new 'r2', r1
        r3 = EvenDoors::Room.new 'r3', r1
        r4 = EvenDoors::Room.new 'r4', r3
        d0 = EvenDoors::Door.new 'd0', r1
        d1 = EvenDoors::Door.new 'd1', r1
        d2 = EvenDoors::Door.new 'd2', r2
        p0 = EvenDoors::Spin.require_p EvenDoors::Particle
        p1 = EvenDoors::Spin.require_p EvenDoors::Particle
        p2 = EvenDoors::Spin.require_p EvenDoors::Particle
        EvenDoors::Spin.send_p p0
        EvenDoors::Spin.send_p p1
        EvenDoors::Spin.send_sys_p p2
        json = JSON.generate spin
        EvenDoors::Spin.clear!
        dom0 = EvenDoors::Spin.json_create( JSON.load( json ) )
        json.should eql JSON.generate(dom0)
    end
    #
end
#
#EOF