Commit b79eccc5 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Bugs estimation added

parent f081cb70
class Application {
private let name: String
private var bugs = Set<Bug>()
public var bugsCount: Int {
return bugs.count
}
init(name: String) {
guard name.count > 0 else {
fatalError("Application should contain name")
}
self.name = name
}
public func add(bug: Bug) {
bugs.insert(bug)
//debugPrint("Bug with name: \"\(bug.name)\" and description \"\(bug.description)\" was added to application with name \"\(name)\"")
}
public func randomBug() -> Bug {
guard bugs.count > 0, let bug = bugs.randomElement() else {
fatalError("Application should contain bugs!")
}
return bug
}
}
\ No newline at end of file
class Bug: Hashable {
public let name: String
public let description: String
init(name: String, description: String) {
guard name.count > 0 else {
fatalError("Bug should contain name")
}
guard description.count > 0 else {
fatalError("Bug should contain description")
}
self.name = name
self.description = description
}
// MARK: Hashable
static func == (lhs: Bug, rhs: Bug) -> Bool {
return lhs.name == rhs.name && lhs.description == rhs.description
}
func hash(into hasher: inout Hasher) {
hasher.combine(name)
hasher.combine(description)
}
}
\ No newline at end of file
class Tester {
private let errorFindProbability: Int
private let name: String
init(name: String, errorFindProbability: Int) {
guard name.count > 0 else {
fatalError("Testers must have names")
}
guard errorFindProbability >= 0, errorFindProbability <= 100 else {
fatalError("Error find probability must be in range 0 - 100%")
}
self.errorFindProbability = errorFindProbability
self.name = name
debugPrint("Tester with name \(name) and error find probability \(errorFindProbability)% was created")
}
public func findBugs(in application: Application) -> [Bug] {
var foundBugs = Set<Bug>()
for round in Range(0...application.bugsCount) {
let searchResult = Int.random(in: 0...100)
let bugFound = searchResult <= errorFindProbability
if bugFound {
var bug = application.randomBug()
//debugPrint("Tester \(name) found a bug \(bug.name)")
foundBugs.insert(bug)
}
}
return Array(foundBugs)
}
}
\ No newline at end of file
// Programming process
let application = Application(name: "Best Corporate Shiny App")
let actualBugsCount = 100
for bugIndex in Range(0..<actualBugsCount) {
let bug = Bug(name: "Bug \(bugIndex)",
description: "Bug \(bugIndex) description")
application.add(bug: bug)
}
// QA process
let testerAlice = Tester(name: "Alice", errorFindProbability: 20)
let testerBob = Tester(name: "Bob", errorFindProbability: 60)
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
var 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
debugPrint("Estimation bugs count (Lincoln Index): \(lincolnIndex)")
debugPrint("Actual bugs count: \(bugsCount)")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment