- This test suite is not exaustive.
- It requires removing the org.* restriction from auto import rules if you are using the IntelliJ project included in the course zip file. This is because the Junit5 development team used the based package org.junit.* instead of junit.* in many of the new libraries.
- It requires adding Junit5 dependencies.
This file contains hidden or 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
// Path project_root/buildSrc/src/main/kotlin | |
object Dependencies { | |
object Kotlin { | |
val stdlib: String = "org.jetbrains.kotlin:kotlin-stdlib:${Versions.kotlin}" | |
val coroutines: String = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutines}" | |
} | |
object Retrofit { | |
val base: String = "com.squareup.retrofit2:retrofit:${Versions.retrofit}" | |
val gson: String = "com.squareup.retrofit2:converter-gson:${Versions.retrofit}" |
This file contains hidden or 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
object Api { | |
private const val endpoint = "https://www.aviationweather.gov/adds/dataserver_current/" | |
private val scalarConverter by lazy { ScalarsConverterFactory.create() } | |
private val jsonConverter by lazy { GsonConverterFactory.create() } | |
private val client by lazy { | |
OkHttpClient.Builder() | |
.addInterceptor { chain -> | |
val original: Request = chain.request() |
This file contains hidden or 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
object CsvMapper { | |
fun decode(rawText: String): Metar { | |
val values = rawText.split(",") | |
return buildMetar(values, skyConditions(values), qualityControlFlags(values)) | |
} | |
private fun buildMetar(values: List<String>, skyCondition: List<SkyCondition>, qualityControlFlags: QualityControlFlags): Metar { | |
// 0:raw_text 1:station_id 2:observation_time 3:latitude 4:longitude 5:temp_c 6:dewpoint_c 7:wind_dir_degrees | |
// 8:wind_speed_kt 9:wind_gust_kt 10:visibility_statute_mi 11:altim_in_hg 12:sea_level_pressure_mb |
This file contains hidden or 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
abstract class AbstractUnitTest { | |
private var counter: Int = 0 | |
private var passed: Int = 0 | |
@BeforeAll | |
abstract fun beforeAll() | |
abstract fun actualMethods(): List<String> | |
abstract fun expectedMethods(): List<String> | |
abstract fun actualProperties(): List<String> | |
abstract fun expectedProperties(): List<String> |
This file contains hidden or 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 kotlin.math.sqrt | |
// See https://www.geeksforgeeks.org/program-sudoku-generator/ | |
class Sudoku(private val N: Int, private val K: Int) { | |
// Convenience value for public operations on the matrix | |
val width get() = N | |
val matrix = Array(N) { IntArray(N) } | |
// square root of N | |
private val sqrt = sqrt(N.toDouble()).toInt() |
This file contains hidden or 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
/** | |
* Name: MyObject | |
* Date: | |
* Description: Tests used to create an empty API for an immutable type MyObject | |
* using test driven design (TDD). | |
* | |
* API Specification: | |
* | |
* public class MyObject { | |
* public MyObject(Object[] objects) // a general constructor description |
This file contains hidden or 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 MissionsRepositoryTests : UnitTest() { | |
private val networkHandler = mockk<NetworkHandler>() | |
private val call = mockk<Call<List<Mission>>>(relaxed = true) | |
private val response = mockk<Response<List<Mission>>>() | |
private val missionService = mockk<MissionService>() | |
@BeforeAll | |
override fun beforeAll() { | |
StdOut.println(Values.suiteTitle(Values.SUITE_TITLE_MISSIONS_REPOSITORY)) | |
} |
This file contains hidden or 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
/** | |
* Name: Al Warren | |
* Date: 6/16/2019 | |
* Description: Test suite for an Immutable object type BaseballElimination. | |
* | |
* API Requirements: | |
* | |
* public BaseballElimination(String filename) // create a baseball division from given filename in format specified below | |
* public int numberOfTeams() // number of teams | |
* public Iterable<String> teams() // all teams |
A simple Java challenge. This really stumped me the first time I ran across it. I made it work but looking at the code made absolutley no sense. Give it a try and let me know how you do.
Consider the following values:
8 1 3
4 0 2
7 6 5
- Store the values in a two-dimensional array of int.
- Move the 0 up by modifying a single index and swapping two values.
NewerOlder