summaryrefslogtreecommitdiffstats
path: root/spec/evendoors_spec.rb
blob: e326107521c26aced6f9777523bf80a53864343b (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
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
begin
    require 'simplecov'
    SimpleCov.start do
        add_filter 'spec'
    end
rescue LoadError
end
#
require 'evendoors'
#
describe EvenDoors do
    #
    it "EvenDoors module should exxists" do
        expect{ EvenDoors }.not_to raise_error(NameError)
    end
    #
    describe EvenDoors::Twirl do
        #
        class MyP < EvenDoors::Particle; end
        #
        it "should correctly manage Particles pool" do
            p0 = EvenDoors::Twirl.require_p EvenDoors::Particle
            p1 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p0===p1).should be_false
            EvenDoors::Twirl.release_p p0
            p2 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p0===p2).should be_true
        end
        #
        it "should correctly manage different Particles classes" do
            p0 = EvenDoors::Twirl.require_p EvenDoors::Particle
            p1 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p0===p1).should be_false
            EvenDoors::Twirl.release_p p0
            p2 = EvenDoors::Twirl.require_p MyP
            p3 = EvenDoors::Twirl.require_p MyP
            (p2===p3).should be_false
            EvenDoors::Twirl.release_p p2
            p4 = EvenDoors::Twirl.require_p MyP
            (p2===p4).should be_true
        end
        #
        it "should correctly release merged data" do
            p0 = EvenDoors::Twirl.require_p EvenDoors::Particle
            p1 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p0===p1).should be_false
            p0.merge! p1
            EvenDoors::Twirl.release_p p0
            p2 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p2===p0).should be_true
            p3 = EvenDoors::Twirl.require_p EvenDoors::Particle
            (p3===p1).should be_true
        end
        #
    end
    #
end