-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
193 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/fixie/generator/momentum/SquareMomentumClass.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package fixie.generator.momentum | ||
|
||
import fixie.generator.number.FloatType | ||
import fixie.generator.quantity.FloatQuantityClass | ||
import fixie.generator.quantity.QuantityUnit | ||
|
||
class SquareMomentumClass( | ||
className: String, | ||
floatType: FloatType, | ||
val momentumClassName: String?, | ||
createNumberExtensions: Boolean | ||
) : FloatQuantityClass(className, floatType, createNumberExtensions) { | ||
|
||
var momentum: MomentumClass? = null | ||
|
||
override fun getSupportedUnits() = listOf(QuantityUnit( | ||
"SQUARE_NEWTON_SECOND", "", "(Ns)^2", "squareNs", 0.0001, 1e6, 1.0 | ||
)) | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/kotlin/fixie/generator/momentum/SquareMomentumClassGenerator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package fixie.generator.momentum | ||
|
||
import fixie.generator.quantity.FloatQuantityClassGenerator | ||
import java.io.PrintWriter | ||
|
||
class SquareMomentumClassGenerator( | ||
writer: PrintWriter, | ||
quantity: SquareMomentumClass, | ||
packageName: String | ||
) : FloatQuantityClassGenerator<SquareMomentumClass>(writer, quantity, packageName) { | ||
|
||
override fun getImports() = | ||
super.getImports() + if (quantity.momentum != null) arrayOf("kotlin.math.sqrt") else emptyArray() | ||
|
||
override fun generateToDoubleComment() { | ||
writer.println("\t/** Gets the square momentum value, in (Ns)^2 */") | ||
} | ||
|
||
override fun generateNumberUnitExtensionFunctions(typeName: String) { | ||
// TODO Why is this not done automatically? | ||
writer.println() | ||
writer.println("val $typeName.squareNs") | ||
writer.println("\tget() = ${quantity.className}.SQUARE_NEWTON_SECOND * this") | ||
} | ||
|
||
override fun generateToString() { | ||
writer.println() | ||
writer.println("\toverride fun toString() = String.format(\"%.2f%s\", value, \"(Ns)^2\")") | ||
} | ||
|
||
override fun generateCompanionContent() { | ||
// TODO Maybe do this automatically | ||
val suffix = if (quantity.floatType.numBytes == 4) "f" else ".0" | ||
writer.println("\t\tval SQUARE_NEWTON_SECOND = ${quantity.className}(1$suffix)") | ||
} | ||
|
||
override fun generateArithmetic() { | ||
super.generateArithmetic() | ||
|
||
if (quantity.momentum != null) { | ||
writer.println() | ||
writer.println("\toperator fun div(right: ${quantity.momentumClassName}) = " + | ||
"${quantity.momentumClassName}.NEWTON_SECOND * toDouble() / right.toDouble()") | ||
} | ||
} | ||
|
||
override fun generateMathFunctions() { | ||
super.generateMathFunctions() | ||
|
||
if (quantity.momentum != null) { | ||
writer.println() | ||
writer.println("fun sqrt(x: ${quantity.className}) = ${quantity.momentumClassName}.NEWTON_SECOND * sqrt(x.value)") | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/fixie/generator/momentum/SquareMomentumTestsGenerator.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fixie.generator.momentum | ||
|
||
import fixie.generator.quantity.FloatQuantityTestsGenerator | ||
import java.io.PrintWriter | ||
|
||
class SquareMomentumTestsGenerator( | ||
writer: PrintWriter, | ||
quantity: SquareMomentumClass, | ||
packageName: String | ||
) : FloatQuantityTestsGenerator<SquareMomentumClass>(writer, quantity, packageName) { | ||
|
||
override fun generateToStringBody() { | ||
writer.println("\t\tassertEquals(\"2.34(Ns)^2\", (${quantity.className}.SQUARE_NEWTON_SECOND * 2.34).toString())") | ||
} | ||
|
||
override fun generateArithmeticBody() { | ||
super.generateArithmeticBody() | ||
|
||
if (quantity.momentum != null) { | ||
writer.println("\t\tassertEquals(2.5, ((10 * ${quantity.className}.SQUARE_NEWTON_SECOND) / " + | ||
"(4 * ${quantity.momentumClassName}.NEWTON_SECOND)).toDouble(), 0.001)") | ||
} | ||
} | ||
|
||
override fun generateMathFunctionsBody() { | ||
super.generateMathFunctionsBody() | ||
|
||
if (quantity.momentum != null) { | ||
writer.println("\t\tassertEquals(3.0, sqrt(9 * ${quantity.className}.SQUARE_NEWTON_SECOND).toDouble(), 0.001)") | ||
} | ||
} | ||
} |
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