import "pkg:/source/rooibos/TestResult.bs"

namespace rooibos
    ' @ignore
    class Stats
        public time = 0
        public ranCount = 0
        public passedCount = 0
        public failedCount = 0
        public crashedCount = 0
        public ignoredCount = 0
        public ignoredTestNames = []
        public hasFailures = false
        public testResult = invalid

        function new()
        end function

        function merge(other as rooibos.Stats) as void
            m.time += other.time
            m.ranCount += other.ranCount
            m.passedCount += other.passedCount
            m.failedCount += other.failedCount
            m.crashedCount += other.crashedCount
            m.ignoredCount += other.ignoredCount
            m.ignoredTestNames.append(other.IgnoredTestNames)
            m.onUpdate()
        end function

        function appendTestResult(result as rooibos.TestResult)
            m.time += result.time
            m.ranCount++
            if result.isCrash then
                m.crashedCount++
            else if result.isFail then
                m.failedCount++
            else if result.isSkipped then
                m.ignoredTestNames.push(result.test.name)
                m.ignoredCount++
            else
                m.passedCount++
            end if

            m.onUpdate()
        end function

        function onUpdate()
            m.hasFailures = m.failedCount > 0 or m.crashedCount > 0
        end function

    end class
end namespace
