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
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html | |
class YFact { | |
// T function returning a T | |
// T -> T | |
public static interface Func<T> { | |
T apply(T n); | |
} | |
// Higher-order function returning a T function |
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
type Foo struct { | |
A int `tag1:"First Tag" tag2:"Second Tag"` | |
B string | |
} | |
func main() { | |
sl := []int{1, 2, 3} | |
greeting := "hello" | |
greetingPtr := &greeting | |
f := Foo{A: 10, B: "Salutations"} |
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
package main | |
import "fmt" | |
import "sort" | |
type EMPTY struct {} | |
var PRESENT EMPTY = EMPTY{} | |
func partition(val int) []string { |
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
switch v.Kind() { | |
case reflect.Map: | |
// Map key must either have string kind, have an integer kind, | |
// or be an encoding.TextUnmarshaler. | |
t := v.Type() | |
switch t.Key().Kind() { | |
case reflect.String, | |
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, | |
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: | |
default: |
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
@RunWith(Parameterized.class) | |
public class CalculatorTest { | |
@Parameters(name = "{index}: CalculatorTest({0})={1}, throws {2}") | |
public static Collection<Object[]> data() { | |
return Arrays.asList(new Object[][]{ | |
{"1 + 1", 2, null}, | |
{"1 + 1 + 1", 3, null}, | |
{"1–1", 0, null}, | |
{"1 * 1", 1, null}, | |
{"1 / 1", 1, null}, |
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
@RunWith(SpringRunner.class) | |
@SpringBootTest | |
public class DemoApplicationTests { | |
@Autowired | |
ApplicationContext ac; | |
@Test | |
public void contextLoads() { | |
Calculator calculator = ac.getBean(Calculator.class); |
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
<plugin> | |
<groupId>org.jacoco</groupId> | |
<artifactId>jacoco-maven-plugin</artifactId> | |
<version>0.8.2</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>prepare-agent</goal> | |
</goals> | |
</execution> |
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
<reporting> | |
<plugins> | |
<plugin> | |
<groupId>org.jacoco</groupId> | |
<artifactId>jacoco-maven-plugin</artifactId> | |
<reportSets> | |
<reportSet> | |
<reports> | |
<!-- select non-aggregate reports --> | |
<report>report</report> |
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
public class CalculatorImpl implements Calculator { | |
public CalculatorImpl() { | |
} | |
@Override | |
public double process(String expression) { | |
String[] tokens = expression.split(" "); | |
Deque<String> operators = new ArrayDeque<>(); | |
Deque<Double> numbers = new ArrayDeque<>(); | |
try { |
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
@Parameters(name = "{index}: CalculatorTest({0})={1}, throws {2}") | |
public static Collection<Object[]> data() { | |
return Arrays.asList(new Object[][]{ | |
{"1 + 1", 2, null}, | |
{"1 + 1 + 1", 3, null}, | |
{"1–1", 0, null}, | |
{"1 * 1", 1, null}, | |
{"1 / 1", 1, null}, | |
{"( 1 + 1 )", 2, null}, | |
{"+", 0, new CalculatorException("Invalid expression: +")}, |
NewerOlder