[Demonstration 1]

[Buggy Method]
public static double[] generateCustomWaveform(Waveform waveform, double amplitude, double frequency) {
    Driver driver;
    switch(waveform) {
        case Sawtooth:
            driver = new Sawtooth("Sawtooth", 0, 0, amplitude, frequency);
            break;
        case SawtoothUpDown:
            driver = new SawtoothUpDown("SawtoothUpDown", 0, 0, amplitude, frequency);
            break;
        case Triangle:
            driver = new Triangle("Triangle", 0, 0, amplitude, frequency);
            break;
        case TriangleUpDown:
            driver = new TriangleUpDown("TriangleUpDown", 0, 0, amplitude, frequency);
            break;
        case Square:
            driver = new Square("Square", amplitude / 2, 0, amplitude / 2, frequency);
            break;
        case SquareUpDown:
            driver = new Square("SquareUpDown", 0, 0, amplitude, frequency);
            break;
        case QuarterSine:
            driver = new QuarterSine("QuarterSine", 0, 0, amplitude, frequency);
            break;
        case HalfSine:
            driver = new HalfSine("HalfSine", 0, 0, amplitude, frequency);
            break;
        case SquareSmooth:
            driver = new SquareSmooth("SquareSmooth", 0, 0, amplitude, frequency);
            break;
        default:
            driver = new SawtoothUpDown("SawtoothUpDown", 0, 0, amplitude, frequency);
            break;
    }
    int counter = 0;
    double[] customWaveform = new double[4096];
    double timeInc = 1 / frequency / 4096;
    do {
        double time = counter * timeInc;
        // / 5.0 to scale between 1 and -1
        customWaveform[counter] = driver.getSignal(time) / 5.0;
    } while (++counter < 4096);
    return customWaveform;
}

[Buggy Hunk]
double timeInc = 1 / frequency / 4096;

[Patch]
double timeInc = 1.0 / frequency / 4096;

[Demonstration 2]

[Buggy Method]
public GameState endTurn(GameState state, String playerName, List<GameAction> actions) {
    RManagerPlayer player = state.getPlayerByName(playerName);
    player.setTurnStatistics(new TurnStatistic());
    logger.debug("Ending turn for player '" + playerName + "'");
    logger.debug("Found '" + actions.size() + "' actions for player '" + playerName + "'");
    // player actions
    for (GameAction gameAction : actions) {
        for (GameActionHandler handler : actionHandlers) {
            if (handler.canHandle(gameAction)) {
                handler.handle(gameAction, player, state);
            }
        }
    }
    // refresh personnel in cities
    refreshCityPersonnel(state);
    // pay monthly costs
    for (Building building : player.getBuildings()) {
        player.pay(building.getMonthlyPersonnelCosts());
        player.getTurnStatistics().increasePersonnelCosts(building.getMonthlyPersonnelCosts());
        player.pay(building.getMonthlyCabinetCosts());
        player.getTurnStatistics().increaseRunningCosts(building.getMonthlyPersonnelCosts());
        logger.debug("Monthly costs of building '" + building.getId() + "' = " + building.getMonthlyPersonnelCosts().add(building.getMonthlyCabinetCosts()));
    }
    // sell meals
    for (Building building : player.getBuildings()) {
        City city = state.getCityById(building.getCityId());
        if (city == null) {
            throw new GameException("City with id '" + building.getCityId() + "' could not be found");
        }
        BigDecimal meals = building.getMonthlyOutput();
        player.getTurnStatistics().increaseCustomers(meals);
        logger.debug("Monthly output of building '" + building.getId() + "' = " + meals);
        // meal price = 10
        BigDecimal earnings = meals.multiply(new BigDecimal(10).multiply(city.getRateOfPriceIncrease()));
        player.earn(earnings);
        player.getTurnStatistics().increaseEarnings(earnings);
        logger.debug("Monthly income of building '" + building.getId() + "' = " + earnings);
    }
    logger.debug("TurnStatistics: " + player.getTurnStatistics().toString());
    return state;
}

[Buggy Hunk]
player.getTurnStatistics().increaseRunningCosts(building.getMonthlyPersonnelCosts());

[Patch]
player.getTurnStatistics().increaseRunningCosts(building.getMonthlyCabinetCosts());

[Demonstration 3]

[Buggy Method]
private int optimizeOrder(int startOrder, double startScore, int minFactor, int maxFactor, final ScoreCache scoreCache) throws StructureException {
    logger.trace("Optimizing orders from {} with prime factors {}-{}", startOrder, primes[minFactor], primes[maxFactor]);
    final double threshold = startScore * scoreThreshold;
    if (minFactor > maxFactor) {
        return -1;
    }
    // Degenerate if <3 samples per period
    // Fails for order > 24 for standard 5deg samples
    if (3 * getAngleIncr() > 2 * PI / startOrder) {
        return -1;
    }
    // Compute score for this order
    double score = scoreCache.get(startOrder);
    logger.trace("Score({}) = {} {}", startOrder, score, score < threshold ? "< " + threshold : "OK");
    if (score < threshold) {
        // Not optimal
        return -1;
    }
    // Still a possible optimum, so search further
    int bestOrder = startOrder;
    for (int p = minFactor; p <= maxFactor; p++) {
        int sub = optimizeOrder(startOrder * primes[p], startScore, p, maxFactor, scoreCache);
        if (sub > bestOrder) {
            bestOrder = sub;
        }
    }
    return bestOrder;
}

[Buggy Hunk]
if( minFactor > maxFactor) {

[Patch]
if( minFactor > maxFactor || startOrder > getMaxOrder()) {