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
#include <stdlib.h> | |
#include <stdio.h> | |
#define DEFAULT_SIZE 16 | |
int no_of_words = 0; //Number of elements in array | |
int array_size = DEFAULT_SIZE; | |
int *stack; //Stack pointer | |
void init_stack() { | |
stack = malloc(sizeof(uint32_t) * DEFAULT_SIZE); |
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
def play_game(start_range, end_range) | |
computer_guess = rand(start_range..end_range) | |
user_guesses = [] | |
puts "Guess a number" | |
user_guess = gets.chomp.to_i | |
while user_guess != computer_guess | |
if user_guesses.include?(user_guess) |
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 getShipmentWithOneBox(): Shipment { | |
return Shipment( | |
id = 1L, | |
boxes = listOf( | |
Box( | |
id = 1L, | |
contents = listOf( | |
Product(id = 1L, name = "Pink Fuzzy Jacket")) | |
) | |
) |
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 getShipmentWithOneBox(): Shipment { | |
return ShipmentBuilder() | |
.withId(1L) | |
.withBoxes( | |
BoxBuilder() | |
.withId(1L) | |
.withContents( | |
ProductBuilder() | |
.withId(1L) | |
.withName("Pink Fuzzy Jacket") |
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
//Lambda without receiver | |
fun buildString ( | |
builderAction: (StringBuilder) -> Unit | |
) : String { | |
val stringBuilder = StringBuilder() | |
builderAction(stringBuilder) | |
return stringBuilder.toString() | |
} | |
val string = buildString { | |
it.append("Hello, ") // Note the need for adding 'it' in front |
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
// Lambda with receiver | |
fun buildString ( | |
builderAction: StringBuilder.() -> Unit // Note the location of the parentheses | |
) : String { | |
val stringBuilder = StringBuilder() | |
stringBuilder.builderAction() // This is now a method on the string builder | |
return stringBuilder.toString() | |
} | |
val string = buildString { | |
append("Hello, ") // Note we no longer need the qualifyer in front |
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 shipmentWithOneBoxWithOneProduct(): Shipment = buildShipment { | |
id = 1L | |
buildBox { | |
id = 1L | |
buildProduct { | |
id = 1L | |
name = "Pink Fuzzy Jacket" | |
} | |
} | |
}.build() |
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 buildShipment( | |
buildShipment: ShipmentTestDataBuilder.() -> Unit | |
): Shipment { | |
val shipmentBuilder = ShipmentTestDataBuilder() | |
shipmentBuilder.buildShipment() | |
return shipmentBuilder.build() | |
} | |
class ShipmentTestDataBuilder( | |
var id: Long = 1L, | |
var boxes: List<Box> = emptyList() |
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 override( | |
buildShipment: ShipmentTestBuilder.() -> Unit | |
): ShipmentTestBuilder { | |
this.buildShipment() | |
return this | |
} |
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
inline fun overrideBox( | |
id: Long, | |
buildBox: BoxTestDataBuilder.() -> Unit | |
) { | |
if (!boxIdExists(id)) { | |
throw IllegalArgumentException("Box with id $id does not exist") | |
} | |
val boxBuilder = BoxTestDataBuilder() | |
val existingBox = getBox(id) | |
boxBuilder.merge(existingBox) |
OlderNewer