Simulator.swift 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class Simulator {

	static func simulate(aliceErrorFindProbability: Int, bobErrorFindProbability: Int, actualBugsCount: Int) {
	
		// Programming process

		let application = Application(name: "Best Corporate Shiny App")

		for bugIndex in 0..<actualBugsCount {

		    let bug = Bug(name: "Bug \(bugIndex)", 
				  description: "Bug \(bugIndex) description")
                    
			application.add(bug: bug)
		}

		// QA process

Ilya Prokhorov's avatar
Ilya Prokhorov committed
19
		let testerAlice = Tester(name: "Alice", errorFindProbability: aliceErrorFindProbability)
Ilya Prokhorov's avatar
Ilya Prokhorov committed
20
		let testerBob = Tester(name: "Bob", errorFindProbability: bobErrorFindProbability)
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

		let bugsFoundedByAlice = testerAlice.findBugs(in: application)
		let bugsFoundedByBob = testerBob.findBugs(in: application)

		debugPrint("Alice found \(bugsFoundedByAlice.count) bugs")
		debugPrint("Bob found \(bugsFoundedByBob.count) bugs")

		// Lincoln Index

		let commonBugs = bugsFoundedByAlice.filter(bugsFoundedByBob.contains)

		guard commonBugs.count > 0 else {

		    fatalError("No common bugs found, one of testers must be lazy") 
    
		}

		debugPrint("Common bugs count: \(commonBugs.count)")

		let lincolnIndex = (bugsFoundedByAlice.count * bugsFoundedByBob.count) / commonBugs.count
		let bugsCount = application.bugsCount

		print("---")
		print("Estimation bugs count: \(lincolnIndex)")
		print("Actual bugs count: \(bugsCount)")	
	
	}

}