This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[versions] | |
agp = "8.5.0" | |
kotlin = "1.9.0" | |
coreKtx = "1.10.1" | |
junit = "4.13.2" | |
junitVersion = "1.1.5" | |
espressoCore = "3.5.1" | |
lifecycleRuntimeKtx = "2.6.1" | |
activityCompose = "1.8.0" | |
composeBom = "2024.04.01" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getFactor(index: Int, draggedIndex: Int): Float { | |
val distance = Math.abs(index - draggedIndex).toFloat() | |
val sigma = 1f // Adjust the sigma for the width of the bell curve | |
val max = .9f | |
// Gaussian function | |
val bellCurve = exp((-distance.pow(2)) / (2 * sigma.pow(2))) | |
// Scale the bell curve to be in the range 0f to 0.8f | |
val scaledValue = bellCurve * max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layout(constraints.maxWidth, totalHeight) { | |
var yPosition = 0 | |
placeables.forEachIndexed { index, placeable -> | |
val dragVal = dragAmount.value | |
//Calculate the new position based on the drag value and the gaussian factor, | |
// where the dragged index has highest factor and decreasing factor along its adjacent elements | |
val newPostion = (yPosition + (dragVal * getFactor(index, draggingItemIndex))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.pointerInput(Unit) { | |
detectVerticalDragGestures( | |
onDragStart = { offset -> | |
draggingItemIndex = (offset.y / itemHeight).toInt() | |
}, | |
onDragEnd = { | |
coroutineScope.launch { | |
dragAmount.animateTo(0f, tween(200, easing = EaseInOut)) | |
draggingItemIndex = -1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
import kotlin.math.pow | |
/** | |
* @author Preyea R. Regmi | |
* Entry point to the division operation | |
* 1) Takes input from CLI as string and parse into decimal format. | |
* 2) Converts the input and divisor into binary string | |
* 3) Performs division on binary representation | |
* 4) Prints Quotient and Remainder in both binary and decimal format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test( | |
"Fetch loan should not fail with any exception when mocked with success response", | |
() { | |
FetchLoanDetail fetchLoanUseCase = | |
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO(3))); | |
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) {}, | |
expectAsync1((error) { | |
expect(error, isNot(isInstanceOf<UseCaseNotImplementedException>()), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LoanDetailResponse { | |
final String _emi; | |
LoanDetailResponse(this._emi); | |
static from(EMICalculator emiCalculator) { | |
return LoanDetailResponse(emiCalculator.calculateEMI().toString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test( | |
"EMI must be 150391.64490861617 for amount = 10,000, rate = 15%, time =24 months", | |
() { | |
FetchLoanDetail fetchLoanUseCase = | |
FetchLoanDetail(MockedSucessRateFetchRepository(LoanDetailDTO("15"))); | |
fetchLoanUseCase.execute( | |
LoanParamRequest(10000, 24), expectAsync1((data) { | |
expect("150391.64490861617",equals( data._emi),reason: "Emi calculation invalid"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Domain Entity responsible for calculating EMI for given params. | |
class EMICalculator { | |
final double amount, rate, time; | |
EMICalculator(this.amount, this.rate, this.time){ | |
if(amount<0) | |
throw ArgumentError("Amount cannot be less than zero"); | |
if(rate<0) | |
throw ArgumentError("Rate cannot be less than zero"); | |
if(time<0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test( | |
"Use case must also fail when fetch loan fails from network", | |
() { | |
FetchLoanDetail fetchLoanUseCase = | |
FetchLoanDetail(MockedFailedRateFetchRepository(RateFetchFailType.NETWORK)); | |
fetchLoanUseCase.execute(LoanParamRequest(100, 2), (data) { | |
}, expectAsync1((error) { | |
expect(error, isNot(isInstanceOf<RateFetchFailException>()), |
NewerOlder