Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Refactorings #1644

Open
dormaayan opened this issue Dec 21, 2018 · 1 comment
Open

Testing Refactorings #1644

dormaayan opened this issue Dec 21, 2018 · 1 comment
Assignees

Comments

@dormaayan
Copy link
Member

dormaayan commented Dec 21, 2018

List of steps for test refactoring:

  1. Convert simple non fluent Junit to simple assertions (TODO: add list)
  2. Convert harmcrest to arithmetical expressions
  3. Consolidate consequtive assertions
  4. Consolidate methods with common setup and different tests
  5. Remove verification of non-exception
  6. Use expected exception instead of try \ catch
  7. Split independent tests
  8. Sane paramatrization of tests
@dormaayan dormaayan self-assigned this Dec 21, 2018
@yossigil
Copy link
Member


import java.math.BigInteger;
import java.util.*;

import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import java.util.function.BiConsumer;

interface Selfie<Self extends Selfie<Self>> {
}

class OO<_1, _2> {
	_1 _1;
	_2 _2;

	public OO(_1 _1, _2 _2) {
		this._1 = _1;
		this._2 = _2;
	}
}

class OI<_1> {
	_1 _1;
	int _2;

	public OI(_1 _1, int _2) {
		this._1 = _1;
		this._2 = _2;
	}
}

class OOs<_1, _2> extends ArrayList<OO<_1, _2>> implements Selfie<OOs<_1, _2>> {
	private static final long serialVersionUID = 1L;
	private List<BiConsumer<_1, _2>> tests = new ArrayList<>();

	public OOs(BiConsumer<_1, _2> f) {
		tests.add(f);

	}

	OOs<_1, _2> against(_1 _1, _2 _2) {
		add(new OO<>(_1, _2));
		return this;
	}

	OOs<_1, _2> and(_1 _1, _2 _2) {
		return against(_1, _2);
	}

	public OOs<_1, _2> go() {
		return this;
	}

	public OOs<_1, _2> to(BiConsumer<A, B> f) {
		return this;
	}
}

class OIs<_1, _2> extends ArrayList<OI<_1>> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	OIs<_1, _2> $(_1 _1, int _2) {
		add(new OI<>(_1, _2));
		return this;
	}

	public OIs<_1, _2> to(BiConsumer<A, B> f, BiConsumer<A, B>... fs) {
		// TODO Auto-generated method stub
		return this;
	}
}

class A {
}

class B {
}

class Main {
	public static void testFib(Integer n, BigInteger b) {
		assert fib(n).equals(b);
	}

	public static BigInteger fib(Integer n) {
		if (n == null)
			return BigInteger.ZERO;
		return fib1(n.intValue());
	}

	public static BigInteger sqrt(Integer n) {
		if (n == null)
			return BigInteger.ZERO;
		return fib1(n.intValue());
	}

	public static BigInteger fib1(int n) {
		if (n <= 1)
			return BigInteger.ZERO;
		else
			return fib1(n - 1).add(fib1(n - 2));
	}

	static int inc(int a) {
		return a + 1;
	}

	public static void main(String[] args) {
		Tuples.to(Main::testFib).against(12, BigInteger.ZERO).and(3, BigInteger.valueOf(3))
				.and(4, BigInteger.valueOf(4)).go();
		Tuples.to(Main::inc).of(0, 1).of(1, 2).of(1, 2);
	}

	static void f(A a, B b) {
	}

	static void g(A a, B b) {
	};

	static B h(A a) {
		return null;
	};
}

class Tuples {
	static <A, B> OOs<A, B> to(BiConsumer<A, B> f) {
		return new OOs<A, B>(f);
	}

	static <A> Os<A> to2(Consumer<A> f) {
		return new Os<A>();
	}

	static IIs to(IntFunction f) {
		return new IIs(f);
	}

}

class IIs {

	private IntFunction f;

	public IIs(IntFunction f) {
		this.f = f;
	}

	public IIs of(int a, int b) {
		return this;
	}

}

class Os<O> {
}

class MapTest {
	static {
		Tuples.to2(MapTest::MapTest);
	}

	private Map<String, String> map;

	MapTest(Map<String, String> map) {
		this.map = map;
	}
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants