const text* = "Hello world!"
echo text
test "Check if text is \"Hello world!\"":
check text == "Hello world!"
The .unique() method for lists is super slow in Groovy, make it as fast as possible
class Uniquer {
static List unique(List x) {
x.groupBy { it }.keySet().collect()
}
}
import org.junit.Test
import static java.lang.System.currentTimeMillis as now
class UniqueTest {
@Test
void "Check if unique exceeds 2 seconds"() {
List<User> users = []
Random rand = new Random()
10000.times { byte[] a = new byte[2]; rand.nextBytes(a); users.add(new User(id: a)) }
println "x"
long a = now()
assert Uniquer.unique(users) instanceof List
assert now() - a < 2000
}
}
class User {
byte[] id
boolean equals(User user) {
user.id == id
}
int hashCode() {
((int) id[0]) << 8 | id[1]
}
}
bool Or(bool a, bool b){ return a ? true : (b ? true : false); } bool Xor(bool a, bool b){ return a ? (b ? false : true) : (b ? true : false); } bool And(bool a, bool b){ return a ? (b ? true : false) : false; }
- bool Or(bool a, bool b){
return a or b;- return a ? true : (b ? true : false);
- }
- bool Xor(bool a, bool b){
return a xor b;- return a ? (b ? false : true) : (b ? true : false);
- }
- bool And(bool a, bool b){
return a and b;- return a ? (b ? true : false) : false;
- }