FunctionTest.java 1.05 KB
package kernel.test;

import kernel.Cell;
import kernel.Grid;
import kernel.LanguageEnum;
import kernel.function.Average;
import kernel.function.Sum;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class FunctionTest {
	
	private List<Cell> cells;
	
	@Before
	public void initData() {
		Grid.language = LanguageEnum.EN;
		this.cells = new ArrayList<>();
		
		Cell a1 = new Cell("A", 1, 10.);
		Cell a2 = new Cell("A", 2, 0.);
		Cell a3 = new Cell("A", 3, 20.);
		
		this.cells.add(a1);
		this.cells.add(a2);
		this.cells.add(a3);
	}
	
	@Test
	public void testSum() {
		Sum sum = new Sum(this.cells);
		
		assertNotNull(sum);
		assertEquals(30, sum.eval(), 0);
		assertEquals("SUM(A1,A2,A3)", sum.toString());
	}
	
	@Test
	public void testAverage() {
		Average average = new Average(this.cells);
		
		assertNotNull(average);
		assertEquals(10, average.eval(), 0);
		assertEquals("AVERAGE(A1,A2,A3)", average.toString());
	}
}