/*
 * Copyright (c) 2016, Swiss Institute of Bioinformatics.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 *  * Neither the name of Oracle nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

package sib.swiss.swissprot;

import org.openjdk.jmh.annotations.*;
import java.nio.ByteBuffer;
import java.util.Random;
@State(Scope.Thread)
public class GuanineCytosineCount {
    private static final int size = 2 * 1024 * 1024;
    private ByteBuffer dna;
    @Setup
    public void setUp(){
	dna = ByteBuffer.allocateDirect(size);
	Random random = new Random();
	for (int i=0;i<size;i++) {
		float next = random.nextFloat();
		if (next < 0.3) {
			dna.put((byte) 'a');
		} else if (next < 0.3) {
			dna.put((byte) 't');
		} else if (next < 0.8) {
			dna.put((byte) 'c');
		} else if (next < 0.99) {
			dna.put((byte) 'g'); 
		} else {
			dna.put((byte) 'n');
		}
	}
    }

    @TearDown
    public void tearDown(){
	    dna=null;
    }

    @Benchmark
    public int countUsingSimpleIfStatements() {
	int a=0,c=0,g=0,t =0,n =0;
	for (int i=0;i<size;i++)
	{
		char nucleotide = (char) dna.get(i);

		if (nucleotide == 'a')
			a++;
		if (nucleotide == 'c')
			c++;
		if (nucleotide == 't')
			t++;
		if (nucleotide == 'g')
			g++;
		if (nucleotide == 'n')
			n++;

	}
	return a+c+g+t+n;
    }
    @Benchmark
    public int countUsingAnArray() {
	int []nucleotides=new int[256];
	for (int i=0;i<size;i++)
	{
		byte nucleotide = dna.get(i);
		nucleotides[nucleotide]++;
	}
	return nucleotides['a']+nucleotides['c']+nucleotides['g']+nucleotides['t']+nucleotides['n'];
    }
}

@@ -2661,32 +2661,117 @@
 %09%7D%0A%09
-return a+c+g+t+n
+int count =a+c+g+t+n;%0A%09assert count == size : %22count should equals the array size%22;%0A    %09return count
 ;%0A    %7D%0A
     
@@ -2766,16 +2766,17 @@
 ;%0A    %7D%0A
+%0A
     @Ben
@@ -2946,22 +2946,27 @@
 ++;%0A%09%7D%0A%09
-return
+int count =
  nucleot
@@ -3044,16 +3044,93 @@
 s%5B'n'%5D;%0A
+%09assert count == size : %22count should equals the array size%22;%0A%09return count;%0A
     %7D%0A%7D%0A

Add assert