All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.adrodoc55.TestBase Maven / Gradle / Ivy

Go to download

MPL is a language that makes it easier to write applications for Minecraft 1.9 or higher. The final result of compiling an MPL application are command blocks that can be imported into your world in various ways. MPL comes with it's own editor that supports syntax- and error-highlighting and has a built in compiler.

There is a newer version: 1.3.2
Show newest version
/*
 * Minecraft Programming Language (MPL): A language for easy development of command block
 * applications including an IDE.
 *
 * © Copyright (C) 2016 Adrodoc55
 *
 * This file is part of MPL.
 *
 * MPL is free software: you can redistribute it and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MPL. If not, see
 * .
 *
 *
 *
 * Minecraft Programming Language (MPL): Eine Sprache für die einfache Entwicklung von Commandoblock
 * Anwendungen, inklusive einer IDE.
 *
 * © Copyright (C) 2016 Adrodoc55
 *
 * Diese Datei ist Teil von MPL.
 *
 * MPL ist freie Software: Sie können diese unter den Bedingungen der GNU General Public License,
 * wie von der Free Software Foundation, Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
 * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
 *
 * MPL wird in der Hoffnung, dass es nützlich sein wird, aber OHNE JEDE GEWÄHRLEISTUNG,
 * bereitgestellt; sogar ohne die implizite Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN
 * BESTIMMTEN ZWECK. Siehe die GNU General Public License für weitere Details.
 *
 * Sie sollten eine Kopie der GNU General Public License zusammen mit MPL erhalten haben. Wenn
 * nicht, siehe .
 */
package de.adrodoc55;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;

import net.karneim.pojobuilder.Builder;

public class TestBase {

  private static final Random RANDOM = new Random(5);

  public static int someInt() {
    return RANDOM.nextInt();
  }

  public static int someInt(int bound) {
    return RANDOM.nextInt(bound);
  }

  /**
   * @param lowerBound inclusive
   * @param upperBound inclusive
   * @return
   */
  public static int someInt(int lowerBound, int upperBound) {
    return RANDOM.nextInt(upperBound + 1 - lowerBound) + lowerBound;
  }

  public static int somePositiveInt() {
    return RANDOM.nextInt(Integer.MAX_VALUE);
  }

  public static int few() {
    return someInt(2, 4);
  }

  public static int several() {
    return someInt(5, 10);
  }

  public static int many() {
    return someInt(11, 100);
  }

  public static Builder $String() {
    return new Builder() {
      @Override
      public String build() {
        return "String" + someInt();
      }
    };
  }

  public static Builder $boolean() {
    return new Builder() {
      @Override
      public Boolean build() {
        return RANDOM.nextBoolean();
      }
    };
  }

  public static > Builder $Enum(Class type) {
    return new Builder() {
      @Override
      public E build() {
        E[] values = type.getEnumConstants();
        return values[someInt(values.length)];
      }
    };
  }

  public static 

P some(Builder

builder) { return builder.build(); } @SafeVarargs public static Builder $oneOf(C... choices) { return $oneOf(Arrays.asList(choices)); } public static Builder $oneOf(Iterable choices) { return new OneOf<>(choices); } public static class OneOf implements Builder { private final Map counter; private final Iterator it; public OneOf(Iterable choices) { int size = Iterables.size(choices); counter = new IdentityHashMap<>(size); it = Iterators.cycle(choices); Iterators.advance(it, someInt(size)); } public int getCount(C choice) { Integer integer = counter.get(choice); if (integer == null) return 0; else return integer; } @Override public C build() { C next = it.next(); counter.put(next, getCount(next) + 1); return next; } } public static

Builder> $listOf(int count, Builder

prototype) { return new Builder>() { @Override public List

build() { return listOf(count, prototype); } }; } @SafeVarargs public static List listOf(E... elements) { return Arrays.asList(elements); } public static

List

listOf(int count, Builder

prototype) { List

list = new ArrayList<>(); for (int i = 0; i < count; i++) { list.add(prototype.build()); } return list; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy