Skip to content

Commit

Permalink
Update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
MiSikora committed Nov 9, 2020
1 parent 9ed39fa commit e060338
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 75 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# IDEA
*.iml
/.idea/
!/.idea/codeStyles/
!/.idea/codeStyles/*

# Gradle
.gradle/
build/
/reports/

# Gradle Androide

# Gradle Android
/local.properties
/captures

Expand Down
452 changes: 452 additions & 0 deletions .idea/codeStyles/Project.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ formatting:
active: true
CommentSpacing:
active: true
# TODO: Enable after https://youtrack.jetbrains.com/issue/KT-10974
# ImportOrdering:
# active: true
Indentation:
ImportOrdering:
active: true
Indentation:
active: false # TODO: https://github.com/pinterest/ktlint/issues/854
indentSize: 2
continuationIndentSize: 4
NoBlankLineBeforeRbrace:
Expand Down Expand Up @@ -226,7 +225,7 @@ style:
maxJumpCount: 1
MaxLineLength:
active: true
maxLineLength: 100
maxLineLength: 120
excludePackageStatements: true
excludeImportStatements: true
excludeCommentStatements: true
Expand All @@ -247,7 +246,7 @@ style:
ProtectedMemberInFinalClass:
active: true
RedundantVisibilityModifierRule:
active: true
active: false
SafeCast:
active: true
SerialVersionUIDInSerializableClass:
Expand Down Expand Up @@ -281,8 +280,6 @@ style:
active: true
UseCheckOrError:
active: true
UseIfInsteadOfWhen:
active: true
UseRequire:
active: true
UselessCallOnNotNull:
Expand Down
24 changes: 12 additions & 12 deletions library/ruler/src/test/java/io/mehow/ruler/DistanceSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ class DistanceSpec : BehaviorSpec({

Then("they can be compared to each other") {
checkAll(
Arb.long(MIN_VALUE, MAX_VALUE),
Arb.long(0L, 999_999_999),
Arb.long(MIN_VALUE, MAX_VALUE),
Arb.long(0L, 999_999_999)
Arb.long(MIN_VALUE, MAX_VALUE),
Arb.long(0L, 999_999_999),
Arb.long(MIN_VALUE, MAX_VALUE),
Arb.long(0L, 999_999_999)
) { meter1, nano1, meter2, nano2 ->
val distance1 = Distance.create(meter1, nano1)
val distance2 = Distance.create(meter2, nano2)
Expand All @@ -172,8 +172,8 @@ class DistanceSpec : BehaviorSpec({
When("I multiply it by a natural number") {
Then("the result is correct") {
checkAll(
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.long(0, 500_000)
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.long(0, 500_000)
) { distance, multiplicand ->
val meters = distance.exactTotalMeters * multiplicand.toBigDecimal()
val storedMeters = meters.toBigInteger().longValueExact()
Expand All @@ -190,8 +190,8 @@ class DistanceSpec : BehaviorSpec({
When("I multiply it by a real number") {
Then("the result is correct") {
checkAll(
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.numericDoubles(0.0, 500_000.0)
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.numericDoubles(0.0, 500_000.0)
) { distance, multiplicand ->
val meters = distance.exactTotalMeters * multiplicand.toBigDecimal()
val nanos = meters.movePointRight(9).toBigInteger()
Expand All @@ -209,8 +209,8 @@ class DistanceSpec : BehaviorSpec({
When("I divide it by a natural number") {
Then("the result is correct") {
checkAll(
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.long(1, 500_000)
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.long(1, 500_000)
) { distance, divisor ->
val meters = distance.exactTotalMeters.divide(divisor.toBigDecimal(), DOWN)
val nanos = meters.movePointRight(9).toBigIntegerExact()
Expand All @@ -228,8 +228,8 @@ class DistanceSpec : BehaviorSpec({
When("I divide it by a real number") {
Then("the result is correct") {
checkAll(
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.numericDoubles(0.000_001, 500_000.0)
DistanceGenerator(Distance.ofKilometers(-1_000), Distance.ofKilometers(1_000)),
Arb.numericDoubles(0.000_001, 500_000.0)
) { distance, divisor ->
val meters = distance.exactTotalMeters.divide(divisor.toBigDecimal(), DOWN)
val nanos = meters.movePointRight(9).toBigInteger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ImperialLengthUnitSpec : BehaviorSpec({

Then("distance can be created from it") {
listOf(
0L to Distance.zero,
1L to Distance.create(meters = 0, nanometers = 25_400_000),
7L to Distance.create(meters = 0, nanometers = 177_800_000),
25L to Distance.create(meters = 0, nanometers = 635_000_000),
133L to Distance.create(meters = 3, nanometers = 378_200_000),
1_680L to Distance.create(meters = 42, nanometers = 672_000_000),
131_296L to Distance.create(meters = 3_334, nanometers = 918_400_000),
MAX_VALUE to Distance.create(meters = 234_273_649_736_111_305, nanometers = 497_800_000)
0L to Distance.zero,
1L to Distance.create(meters = 0, nanometers = 25_400_000),
7L to Distance.create(meters = 0, nanometers = 177_800_000),
25L to Distance.create(meters = 0, nanometers = 635_000_000),
133L to Distance.create(meters = 3, nanometers = 378_200_000),
1_680L to Distance.create(meters = 42, nanometers = 672_000_000),
131_296L to Distance.create(meters = 3_334, nanometers = 918_400_000),
MAX_VALUE to Distance.create(meters = 234_273_649_736_111_305, nanometers = 497_800_000)
).forEach { (inches, expected) ->
unit.toDistance(inches) shouldBe expected
Distance.ofInches(inches) shouldBe expected
Expand All @@ -37,14 +37,14 @@ class ImperialLengthUnitSpec : BehaviorSpec({

Then("distance can be created from it") {
listOf(
0L to Distance.zero,
1L to Distance.ofNanometers(304_800_000),
7L to Distance.create(meters = 2, nanometers = 133_600_000),
25L to Distance.create(meters = 7, nanometers = 620_000_000),
133L to Distance.create(meters = 40, nanometers = 538_400_000),
1_680L to Distance.create(meters = 512, nanometers = 64_000_000),
131_296L to Distance.create(meters = 40_019, nanometers = 20_800_000),
MAX_VALUE to Distance.create(meters = 2_811_283_796_833_335_665, nanometers = 973_600_000)
0L to Distance.zero,
1L to Distance.ofNanometers(304_800_000),
7L to Distance.create(meters = 2, nanometers = 133_600_000),
25L to Distance.create(meters = 7, nanometers = 620_000_000),
133L to Distance.create(meters = 40, nanometers = 538_400_000),
1_680L to Distance.create(meters = 512, nanometers = 64_000_000),
131_296L to Distance.create(meters = 40_019, nanometers = 20_800_000),
MAX_VALUE to Distance.create(meters = 2_811_283_796_833_335_665, nanometers = 973_600_000)
).forEach { (feet, expected) ->
unit.toDistance(feet) shouldBe expected
Distance.ofFeet(feet) shouldBe expected
Expand All @@ -60,14 +60,14 @@ class ImperialLengthUnitSpec : BehaviorSpec({

Then("distance can be created from it") {
listOf(
0L to Distance.zero,
1L to Distance.ofNanometers(914_400_000),
7L to Distance.create(meters = 6, nanometers = 400_800_000),
25L to Distance.create(meters = 22, nanometers = 860_000_000),
133L to Distance.create(meters = 121, nanometers = 615_200_000),
1_680L to Distance.create(meters = 1_536, nanometers = 192_000_000),
131_296L to Distance.create(meters = 120_057, nanometers = 62_400_000),
MAX_VALUE to Distance.create(meters = 8_433_851_390_500_006_997, nanometers = 920_800_000)
0L to Distance.zero,
1L to Distance.ofNanometers(914_400_000),
7L to Distance.create(meters = 6, nanometers = 400_800_000),
25L to Distance.create(meters = 22, nanometers = 860_000_000),
133L to Distance.create(meters = 121, nanometers = 615_200_000),
1_680L to Distance.create(meters = 1_536, nanometers = 192_000_000),
131_296L to Distance.create(meters = 120_057, nanometers = 62_400_000),
MAX_VALUE to Distance.create(meters = 8_433_851_390_500_006_997, nanometers = 920_800_000)
).forEach { (yards, expected) ->
unit.toDistance(yards) shouldBe expected
Distance.ofYards(yards) shouldBe expected
Expand All @@ -84,13 +84,13 @@ class ImperialLengthUnitSpec : BehaviorSpec({
When("value does not overflow") {
Then("distance can be created from it") {
listOf(
0L to Distance.zero,
1L to Distance.create(meters = 1_609, nanometers = 344_000_000),
7L to Distance.create(meters = 11_265, nanometers = 408_000_000),
25L to Distance.create(meters = 40_233, nanometers = 600_000_000),
133L to Distance.create(meters = 214_042, nanometers = 752_000_000),
1_680L to Distance.create(meters = 2_703_697, nanometers = 920_000_000),
131_296L to Distance.create(meters = 211_300_429, nanometers = 824_000_000)
0L to Distance.zero,
1L to Distance.create(meters = 1_609, nanometers = 344_000_000),
7L to Distance.create(meters = 11_265, nanometers = 408_000_000),
25L to Distance.create(meters = 40_233, nanometers = 600_000_000),
133L to Distance.create(meters = 214_042, nanometers = 752_000_000),
1_680L to Distance.create(meters = 2_703_697, nanometers = 920_000_000),
131_296L to Distance.create(meters = 211_300_429, nanometers = 824_000_000)
).forEach { (miles, expected) ->
unit.toDistance(miles) shouldBe expected
Distance.ofMiles(miles) shouldBe expected
Expand Down
44 changes: 22 additions & 22 deletions library/ruler/src/test/java/io/mehow/ruler/LengthSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ class LengthSpec : BehaviorSpec({
When("they are added") {
Then("unit of the left operand is preserved") {
checkAll(
DistanceGenerator(
min = Distance.create(MIN_VALUE / 2 + 1, 500_000_000),
max = Distance.create(MAX_VALUE / 2 - 1, 500_000_000)
),
DistanceUnitGenerator,
DistanceGenerator(
min = Distance.create(MIN_VALUE / 2 + 1, 500_000_000),
max = Distance.create(MAX_VALUE / 2 - 1, 500_000_000)
),
DistanceUnitGenerator
DistanceGenerator(
min = Distance.create(MIN_VALUE / 2 + 1, 500_000_000),
max = Distance.create(MAX_VALUE / 2 - 1, 500_000_000)
),
DistanceUnitGenerator,
DistanceGenerator(
min = Distance.create(MIN_VALUE / 2 + 1, 500_000_000),
max = Distance.create(MAX_VALUE / 2 - 1, 500_000_000)
),
DistanceUnitGenerator
) { distance1, unit1, distance2, unit2 ->
val length1 = DistanceUnitGenerator.createLength(distance1, unit1)
val length2 = DistanceUnitGenerator.createLength(distance2, unit2)
Expand All @@ -50,16 +50,16 @@ class LengthSpec : BehaviorSpec({
When("they are subtracted") {
Then("unit of the left operand is preserved") {
checkAll(
DistanceGenerator(
min = Distance.ofMeters(MIN_VALUE / 2 + 1),
max = Distance.ofMeters(MAX_VALUE / 2 - 1)
),
DistanceUnitGenerator,
DistanceGenerator(
min = Distance.ofMeters(MIN_VALUE / 2 + 1),
max = Distance.ofMeters(MAX_VALUE / 2 - 1)
),
DistanceUnitGenerator
DistanceGenerator(
min = Distance.ofMeters(MIN_VALUE / 2 + 1),
max = Distance.ofMeters(MAX_VALUE / 2 - 1)
),
DistanceUnitGenerator,
DistanceGenerator(
min = Distance.ofMeters(MIN_VALUE / 2 + 1),
max = Distance.ofMeters(MAX_VALUE / 2 - 1)
),
DistanceUnitGenerator
) { distance1, unit1, distance2, unit2 ->
val length1 = DistanceUnitGenerator.createLength(distance1, unit1)
val length2 = DistanceUnitGenerator.createLength(distance2, unit2)
Expand Down Expand Up @@ -182,15 +182,15 @@ private fun BehaviorSpec.checkImperialUnit(
When("I auto unit it") {
Then("it uses $unit as a unit") {
checkAll(
DistanceGenerator(Distance.of(1, unit), Distance.of(maxRange, unit))
DistanceGenerator(Distance.of(1, unit), Distance.of(maxRange, unit))
) { distance ->
val length = distance.toLength(ImperialLengthUnit.values().random()).withAutoUnit()

length.unit shouldBeSameInstanceAs unit
}

checkAll(
DistanceGenerator(Distance.of(-maxRange, unit), Distance.of(-1, unit))
DistanceGenerator(Distance.of(-maxRange, unit), Distance.of(-1, unit))
) { distance ->
val length = distance.toLength(ImperialLengthUnit.values().random()).withAutoUnit()

Expand Down

0 comments on commit e060338

Please sign in to comment.