Skip to content

Commit

Permalink
feat(types): add toProtected function for numeric types
Browse files Browse the repository at this point in the history
  • Loading branch information
vfmunhoz committed Aug 1, 2021
1 parent 2e8b2da commit 94e952e
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedByte(val value: Byte) : Comparable<ProtectedByte> {
override fun toString(): String = value.obfuscate()
}

fun Byte.toProtected() = ProtectedByte(this)

// Primitive + protected
operator fun Byte.plus(protectedValue: ProtectedByte): Int = this + protectedValue.value
operator fun Byte.plus(protectedValue: ProtectedShort): Int = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedDouble(val value: Double) : Comparable<ProtectedDouble> {
override fun toString(): String = value.obfuscate()
}

fun Double.toProtected() = ProtectedDouble(this)

// Primitive + protected
operator fun Double.plus(protectedValue: ProtectedByte): Double = this + protectedValue.value
operator fun Double.plus(protectedValue: ProtectedShort): Double = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedFloat(val value: Float) : Comparable<ProtectedFloat> {
override fun toString(): String = value.obfuscate()
}

fun Float.toProtected() = ProtectedFloat(this)

// Primitive + protected
operator fun Float.plus(protectedValue: ProtectedByte): Float = this + protectedValue.value
operator fun Float.plus(protectedValue: ProtectedShort): Float = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedInt(val value: Int) : Comparable<ProtectedInt> {
override fun toString(): String = value.obfuscate()
}

fun Int.toProtected() = ProtectedInt(this)

// Primitive + protected
operator fun Int.plus(protectedValue: ProtectedByte): Int = this + protectedValue.value
operator fun Int.plus(protectedValue: ProtectedShort): Int = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedLong(val value: Long) : Comparable<ProtectedLong> {
override fun toString(): String = value.obfuscate()
}

fun Long.toProtected() = ProtectedLong(this)

// Primitive + protected
operator fun Long.plus(protectedValue: ProtectedByte): Long = this + protectedValue.value
operator fun Long.plus(protectedValue: ProtectedShort): Long = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ value class ProtectedShort(val value: Short) : Comparable<ProtectedShort> {
override fun toString(): String = value.obfuscate()
}

fun Short.toProtected() = ProtectedShort(this)

// Primitive + protected
operator fun Short.plus(protectedValue: ProtectedByte): Int = this + protectedValue.value
operator fun Short.plus(protectedValue: ProtectedShort): Int = this + protectedValue.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedByteTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedByteTest {
private val maxProtected = ProtectedByte(Byte.MAX_VALUE)
private val minProtected = ProtectedByte(Byte.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedByte>(primitiveByte.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Byte type`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedDoubleTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedDoubleTest {
private val maxProtectedDouble = ProtectedDouble(Double.MAX_VALUE)
private val minProtectedDouble = ProtectedDouble(Double.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedDouble>(primitiveDouble.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Double type`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedFloatTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedFloatTest {
private val maxProtectedFloat = ProtectedFloat(Float.MAX_VALUE)
private val minProtectedFloat = ProtectedFloat(Float.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedFloat>(primitiveFloat.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Float type`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedIntTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedIntTest {
private val maxProtected = ProtectedInt(Int.MAX_VALUE)
private val minProtected = ProtectedInt(Int.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedInt>(primitiveInt.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Int type`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedLongTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedLongTest {
private val maxProtectedLong = ProtectedLong(Long.MAX_VALUE)
private val minProtectedLong = ProtectedLong(Long.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedLong>(primitiveLong.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Long type`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.vfmunhoz.protectedtypes.types

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

internal class ProtectedShortTest {

Expand All @@ -22,6 +23,11 @@ internal class ProtectedShortTest {
private val maxProtected = ProtectedShort(Short.MAX_VALUE)
private val minProtected = ProtectedShort(Short.MIN_VALUE)

@Test
fun `validates the transformation to protected value`() {
assertIs<ProtectedShort>(primitiveShort.toProtected())
}

// Unary operators
@Test
fun `test the unary plus operator compared to Short type`() {
Expand Down

0 comments on commit 94e952e

Please sign in to comment.