Skip to content

Commit

Permalink
chore: add TransactionModel and function for value generation
Browse files Browse the repository at this point in the history
  • Loading branch information
arieldossantos committed Nov 14, 2020
1 parent e9ebaa5 commit 596fad3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.arieldossantos.cuddlytrain.models

import java.sql.Timestamp

/**
* Transaction model
*
* @param descricao Descrição da transação
* @param data Data da transação
* @param valor Valor da transação
*/
class TransactionModel(val descricao: String, val data: Timestamp, val valor: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ object Generator {
fun totalTransactionsInPeriod(id: Int, month: Int): Int {
return General.getFirstDigit(id) * month
}


/**
* Generate a random transaction value
*
* @param id user id
* @param year current year
*/
fun generateTransactionValue(id: Int, year: Int, transactionIndex: Int): Int {
return General.getFirstDigit(id) * General.getFirstDigit(year) * transactionIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ class GeneratorTest {
Assert.assertSame(Generator.totalTransactionsInPeriod(3423, 3), 9)
Assert.assertSame(Generator.totalTransactionsInPeriod(723, 12), 84)
}

/**
* Test generation of transaction value
*/
@Test
fun testGenerateTransactionValue() {
Assert.assertSame(Generator.generateTransactionValue(12243, 2020, 1), 2)
Assert.assertSame(Generator.generateTransactionValue(3423, 2019, 12), 72)
Assert.assertSame(Generator.generateTransactionValue(723, 1997, 5), 35)
}
}

0 comments on commit 596fad3

Please sign in to comment.