Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main/scala/uk/gov/hmrc/domain/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Generator(random: Random = new Random) extends Modulus23Check {
}

def atedUtrBatch(amountToGenerate: Int): List[AtedUtr] = {
require(amountToGenerate <= 900000, throw new IllegalArgumentException("Can't generate more than 9000000 unique AtedUtrs, specify a smaller value for amount"))
require(amountToGenerate <= 900000, throw new IllegalArgumentException("Can't generate more than 900000 unique AtedUtrs, specify a smaller value for amount"))
val atedUtrs: ListBuffer[AtedUtr] = ListBuffer()
var start = 100000
for (a <- 0 until amountToGenerate) {
Expand All @@ -49,4 +49,24 @@ class Generator(random: Random = new Random) extends Modulus23Check {
AtedUtr(f"X${checkCharacter}AT00000$suffix")
}

def nextAgentBusinessUtr: AgentBusinessUtr = {
val suffix = f"${random.nextInt(1000000)}%07d"
val weighting = s"ARN$suffix"
val checkCharacter = calculateCheckCharacter(weighting)
AgentBusinessUtr(f"${checkCharacter}ARN$suffix")
}

def agentBusinessUtrBatch(amountToGenerate: Int): List[AgentBusinessUtr] = {
require(amountToGenerate <= 9999999, throw new IllegalArgumentException("Can't generate more than 9999999 unique AgentBusinessUtr, specify a smaller value for amount"))
val agentBusinessUtrs: ListBuffer[AgentBusinessUtr] = ListBuffer()
var start = 0
for (a <- 0 until amountToGenerate) {
val stringToWeight = f"ARN$start%07d"
val checkChar = calculateCheckCharacter(stringToWeight)
agentBusinessUtrs.++=(Seq(AgentBusinessUtr(s"$checkChar$stringToWeight")))
start = start + 1
}
agentBusinessUtrs.toList
}

}
13 changes: 13 additions & 0 deletions src/test/scala/uk/gov/hmrc/domain/GeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ class GeneratorSpec extends WordSpec with Checkers {
}

}

"AgentBusinessUtr Generation" should {

"generate valid AgentBusinessUtr for all random seeds" in {
check(Prop.forAll { (seed: Int) => AgentBusinessUtr.isValid(new Generator(seed).nextAgentBusinessUtr.utr)})
}

"generate a batch of unique AgentBusinessUtr" in {
val agentBusinessUtrs = new Generator().agentBusinessUtrBatch(100000)
assert(agentBusinessUtrs.distinct.length == agentBusinessUtrs.length)
}

}
}