Store example count instead of recalculating

This commit is contained in:
Michael Miller 2018-10-14 19:08:07 -06:00
parent bcb68a5856
commit 155e9ec81a

View file

@ -15,6 +15,7 @@ module Spectator
def children=(children : Array(ExampleComponent)) def children=(children : Array(ExampleComponent))
raise "Attempted to reset example group children" if @children raise "Attempted to reset example group children" if @children
@children = children @children = children
@example_count = children.sum(&.example_count)
end end
def each def each
@ -27,9 +28,7 @@ module Spectator
children.each children.each
end end
def example_count : Int getter example_count = 0
children.sum(&.example_count)
end
def [](index : Int) : Example def [](index : Int) : Example
raise IndexError.new if index < 0 raise IndexError.new if index < 0