func()

in coverage/coverage.go [219:321]


func (m *Model) CountCoverage() (int, int) {
	if m == nil || m.IsReadOnly {
		return 0, 0
	}

	m.CoveredCount = 0
	m.TotalCount = 0

	if m.Enum != nil {
		m.EnumCoveredCount = 0
		m.EnumTotalCount = len(*m.Enum)
		for _, isCovered := range *m.Enum {
			if isCovered {
				m.EnumCoveredCount++
			}
		}
	}

	if m.Bool != nil {
		m.BoolCoveredCount = 0
		for _, isCovered := range *m.Bool {
			if isCovered {
				m.BoolCoveredCount++
			}
		}
	}

	if m.Item != nil {
		covered, total := m.Item.CountCoverage()
		m.CoveredCount = covered
		m.TotalCount = total
	}

	if m.Properties != nil {
		for _, v := range *m.Properties {
			if v.IsReadOnly {
				continue
			}
			if v.Item != nil && v.Item.IsReadOnly {
				continue
			}
			covered, total := v.CountCoverage()
			m.CoveredCount += covered
			m.TotalCount += total
			if v.Variants != nil {
				for _, variant := range *v.Variants {
					covered, total := variant.CountCoverage()
					m.CoveredCount += covered
					m.TotalCount += total
				}
			}
			if v.Item != nil && v.Item.Variants != nil {
				for _, variant := range *v.Item.Variants {
					covered, total := variant.CountCoverage()
					m.CoveredCount += covered
					m.TotalCount += total
				}
			}
		}
	}

	if m.IsRoot {
		if m.Variants != nil {
			for _, v := range *m.Variants {
				v.CountCoverage()
			}
		}

		if m.Item != nil && m.Item.Variants != nil {
			for _, v := range *m.Item.Variants {
				v.CountCoverage()
			}
		}
	}

	if m.TotalCount == 0 {
		m.TotalCount = 1
	}
	if m.TotalCount == 1 && m.IsAnyCovered {
		m.CoveredCount = 1
	}

	m.IsFullyCovered = m.TotalCount > 0 && m.CoveredCount == m.TotalCount

	if m.IsRoot {
		m.RootCoveredCount = m.CoveredCount
		m.RootTotalCount = m.TotalCount
		if m.Variants != nil {
			for _, v := range *m.Variants {
				m.RootCoveredCount += v.CoveredCount
				m.RootTotalCount += v.TotalCount
			}
		}
		if m.Item != nil && m.Item.Variants != nil {
			for _, v := range *m.Item.Variants {
				m.RootCoveredCount += v.CoveredCount
				m.RootTotalCount += v.TotalCount
			}
		}
	}

	return m.CoveredCount, m.TotalCount
}