本文整理了Java中net.java.quickcheck.Generator
类的一些代码示例,展示了Generator
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Generator
类的具体详情如下:
包路径:net.java.quickcheck.Generator
类名称:Generator
[英]A generator creates instances of type T supposed to be checked against a Characteristic specification.
[中]生成器创建T类型的实例,该实例应根据特征规范进行检查。
代码示例来源:origin: lenskit/lenskit
@Override
public Rating next() {
long id = ids.next();
while (usedIds.contains(id)) {
id = ids.next();
}
usedIds.add(id);
RatingBuilder rb = Rating.newBuilder()
.setId(id)
.setUserId(userIds.next())
.setItemId(itemIds.next())
.setRating(values.next());
if (timestamps != null) {
rb.setTimestamp(timestamps.next());
}
return rb.build();
}
}
代码示例来源:origin: lenskit/lenskit
private List<Rating> makeRatings() {
Generator<Rating> rgen = ratings();
int n = integers(10, 1000).next();
return Stream.generate(rgen::next)
.limit(n)
.collect(Collectors.toList());
}
代码示例来源:origin: lenskit/lenskit
@Test
public void testCollectMany() {
for (List<Long> ids: someLists(longs(), 10, 100)) {
List<Double> values = lists(doubles(), ids.size()).next();
ResultList results = IntStream.range(0, ids.size())
.mapToObj(i -> Results.create(ids.get(i), values.get(i)))
.collect(Results.listCollector());
assertThat(results.stream().map(Result::getId).collect(Collectors.toList()),
equalTo(ids));
assertThat(results.stream().map(Result::getScore).collect(Collectors.toList()),
equalTo(values));
}
}
代码示例来源:origin: lenskit/lenskit
@Test
public void testParallelCollect() {
for (List<Long> ids: someLists(longs(), 100, 10000)) {
List<Double> values = lists(doubles(), ids.size()).next();
ResultList results = IntStream.range(0, ids.size())
.parallel()
.mapToObj(i -> Results.create(ids.get(i), values.get(i)))
.collect(Results.listCollector());
assertThat(results.stream().map(Result::getId).collect(Collectors.toList()),
equalTo(ids));
assertThat(results.stream().map(Result::getScore).collect(Collectors.toList()),
equalTo(values));
}
}
}
代码示例来源:origin: lenskit/lenskit
@Test
public void testRandomSearchesPresent() {
for (List<Long> keys: someSortedLists(longs())) {
List<Long> deduped = Lists.newArrayList(Sets.newLinkedHashSet(keys));
long key = integers(0, deduped.size()).next();
BinarySearch search = BinarySearch.forList(key, deduped);
assertThat(search.search(0, keys.size()),
equalTo(Collections.binarySearch(deduped, key)));
}
}
代码示例来源:origin: lenskit/lenskit
@Test
public void testRandomSearches() {
for (List<Long> keys: someSortedLists(longs())) {
List<Long> deduped = Lists.newArrayList(Sets.newLinkedHashSet(keys));
long key = longs().next();
BinarySearch search = BinarySearch.forList(key, deduped);
int rv = search.search(0, keys.size());
assertThat(search.search(0, keys.size()),
equalTo(Collections.binarySearch(deduped, key)));
int idx = BinarySearch.resultToIndex(rv);
if (deduped.isEmpty()) {
assertThat(idx, equalTo(0));
} else if (idx == deduped.size()) {
assertThat(key, greaterThan(deduped.get(deduped.size() - 1)));
} else {
assertThat(key, lessThanOrEqualTo(deduped.get(idx)));
}
}
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override
public T next() {
i++;
return content.next();
}
代码示例来源:origin: lenskit/lenskit
/**
* Use random lists to test that we always find the *first* matching element.
*/
@Test
public void testRandomSearchesFindFirst() {
for (List<String> keys: someNonEmptyLists(strings())) {
Collections.sort(keys);
// pick an element to duplicate
int toDup = integers(0, keys.size() - 1).next();
// and # of times to duplicate
int ndups = integers(0, 10).next();
String dupKey = keys.get(toDup);
for (int i = 0; i < ndups; i++) {
keys.add(toDup, dupKey);
}
BinarySearch search = BinarySearch.forList(dupKey, keys);
int rv = search.search(0, keys.size());
assertThat(rv, greaterThanOrEqualTo(0));
assertThat(search.search(0, keys.size()),
lessThanOrEqualTo(Collections.binarySearch(keys, dupKey)));
assertThat(keys.get(rv), equalTo(dupKey));
if (rv > 0) {
// this is the first one
assertThat(keys.get(rv-1), lessThan(dupKey));
}
}
}
代码示例来源:origin: lenskit/lenskit
byte key = bytes().next();
BinarySearch search = BinarySearch.forList(key, keys);
int start = integers(0, keys.size()).next();
int end = integers(start, keys.size()).next();
代码示例来源:origin: lenskit/lenskit
@Test
public void testRandomMaps() {
for (Map<Long,Double> map: someMaps(longs(), doubles())) {
Long2DoubleSortedArrayMap vec = Long2DoubleSortedArrayMap.create(map);
Set<Long> picked = sets(map.keySet()).next();
Set<Long> extra = sets(longs()).next();
LongSortedSet wanted = LongUtils.setUnion(LongUtils.asLongSet(picked), LongUtils.asLongSet(extra));
Long2DoubleSortedMap sv = vec.subMap(wanted);
assertThat(sv.keySet(), everyItem(isIn(wanted)));
assertThat(sv.keySet(), containsInAnyOrder(picked.toArray()));
assertThat(sv.entrySet(), everyItem(isIn(map.entrySet())));
}
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override
public T next() {
Generator<T> generator = generators.get(index++ % generators.size());
return generator.next();
}
}
代码示例来源:origin: com.io7m.jregions/com.io7m.jregions.generators
@Override
public AreaSizeBI next()
{
return AreaSizeBI.of(this.gen.next(), this.gen.next());
}
}
代码示例来源:origin: com.io7m.jregions/com.io7m.jregions.generators
@Override
public AreaSizeBD next()
{
return AreaSizeBD.of(this.gen.next(), this.gen.next());
}
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override public Map<K, V> next() {
Map<K, V> next = new HashMap<K, V>();
for(K key : keys.next()) next.put(key, values.next());
return next;
}
}
代码示例来源:origin: net.java.quickcheck/quickcheck
public Object[] next() {
ArrayList<Object> next = new ArrayList<Object>(generators.length);
for (Generator<?> gen : generators) {
next.add(gen.next());
}
return next.toArray();
}
}
代码示例来源:origin: lenskit/lenskit
@Before
public void initialize() throws IOException {
predictOutputFile = folder.newFile("predictions.csv");
List<Rating> ratings = new ArrayList<>();
Generator<Rating> rgen = LenskitGenerators.ratings();
Set<Pair<Long,Long>> used = new HashSet<>();
while (ratings.size() < RATING_COUNT) {
Rating r = rgen.next();
long uid = r.getUserId() % 5;
Pair<Long,Long> ui = ImmutablePair.of(uid, r.getItemId());
if (used.contains(ui)) {
continue;
}
used.add(ui);
Rating r2 = r.copyBuilder()
.setUserId(r.getUserId() % 5)
.build();
ratings.add(r2);
}
assumeThat(ratings, hasSize(RATING_COUNT));
dao = StaticDataSource.fromList(ratings).get();
LenskitConfiguration config = new LenskitConfiguration();
config.bind(ItemScorer.class).to(UserMeanItemScorer.class);
config.bind(UserMeanBaseline.class, ItemScorer.class).to(ItemMeanRatingItemScorer.class);
tempEval.setRebuildPeriod(1L);
tempEval.setDataSource(dao);
tempEval.setAlgorithm("UserMeanBaseline", config);
tempEval.setOutputFile(predictOutputFile);
}
代码示例来源:origin: lenskit/lenskit
@Test
public void testCreateWithLists() {
for (Set<Long> keys: someSets(longs(), integers(0, 500))) {
LongSortedSet sorted = LongUtils.packedSet(keys);
SortedKeyIndex dom = SortedKeyIndex.fromCollection(keys);
double[] values = new double[dom.size()];
for (int i = 0; i < dom.size(); i++) {
values[i] = doubles().next();
}
Long2DoubleSortedMap map = new Long2DoubleSortedArrayMap(dom, values);
assertThat(map.size(), equalTo(dom.size()));
assertThat(map.size(), equalTo(keys.size()));
if (map.size() > 0) {
assertThat(map.entrySet().first().getKey(), equalTo(sorted.firstLong()));
assertThat(map.entrySet().last().getKey(), equalTo(sorted.lastLong()));
assertThat(map.firstLongKey(), equalTo(sorted.firstLong()));
assertThat(map.lastLongKey(), equalTo(sorted.lastLong()));
}
assertThat(map.keySet(), equalTo(sorted));
for (Long k: keys) {
assertThat(map.containsKey(k), equalTo(true));
}
}
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override
public String next() {
int size = length.next();
StringBuilder builder = new StringBuilder();
for (int count = 0; count < size; count++) {
builder.append(characters.next());
}
return builder.toString();
}
代码示例来源:origin: net.java.quickcheck/quickcheck
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
return definition.retrieveMapping(method).next();
}
代码示例来源:origin: lenskit/lenskit
/**
* Method to compute the data points. Split out so that errors it throws get reported.
*/
@BeforeClass
public static void makeDataPoints() {
KeyData[] data = new KeyData[10];
Generator<Long> intGen = longs(Integer.MIN_VALUE, Integer.MAX_VALUE);
Generator<Long> longGen = longs(Integer.MAX_VALUE + 1L, Long.MAX_VALUE);
for (int i = 0; i < 10; i++) {
Generator<List<Long>> listGen;
if (i % 2 == 0) {
// generate ints
listGen = sortedLists(uniqueValues(intGen), 25, 25);
} else {
// generate longs
listGen = sortedLists(uniqueValues(longGen), 25, 25);
}
List<Long> nums = listGen.next();
data[i] = new KeyData(nums);
}
DATA_POINTS = data;
}
内容来源于网络,如有侵权,请联系作者删除!