<commit_before>package org.cytoscape.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.Assert;

import org.cytoscape.equations.Equation;
import org.cytoscape.equations.internal.EquationCompilerImpl;
import org.cytoscape.equations.internal.EquationParserImpl;
import org.junit.Before;
import org.junit.Test;

public class EquationTest {
	private TableTestSupport support;
	private EquationParserImpl parser;

	@Before
	public void setUp() {
		support = new TableTestSupport();
		parser = new EquationParserImpl();
	}

	Equation parseEquation(String equation, CyTable context) {
		Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
		for (CyColumn column : context.getColumns()) {
			typeMap.put(column.getName(), column.getType());
		}
		EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
		Assert.assertTrue(compiler.compile(equation, typeMap));
		return compiler.getEquation();
	}
	
	@Test
	public void testVirtualColumnEquation() {
		CyTableFactory factory = support.getTableFactory();
		CyTable table1 = factory.createTable("Table 1", "SUID", Long.class, true, true);
		CyTable table2 = factory.createTable("Table 2", "SUID", Long.class, true, true);
		table1.createColumn("name", String.class, false);
		table1.createColumn("real", String.class, false);
		table2.createColumn("name", String.class, false);
		table2.addVirtualColumn("virtual", "real", table1, "SUID", false);
		
		CyRow row1 = table1.getRow(1L);
		row1.set("name", "1");
		
		CyRow row2 = table2.getRow(1L);
		row2.set("name", "2");
		
		row2.set("virtual", parseEquation("=$name", table2));
		
		// Equation should be propagated to both tables
		Assert.assertNotNull(row1.getRaw("real"));
		Assert.assertNotNull(row2.getRaw("virtual"));
		
		// Equation should yield different values depending on context
		Assert.assertEquals("1", row1.get("real", String.class));
		Assert.assertEquals("2", row2.get("virtual", String.class));

		// Overwrite equation with normal attribute.  Both ends of
		// VirtualColumn should give the same answer.
		row1.set("real", "3");
		Assert.assertEquals("3", row1.get("real", String.class));
		Assert.assertEquals("3", row2.get("virtual", String.class));
	}
	
	@Test
	public void testVirtualColumnListEquation() {
		CyTableFactory factory = support.getTableFactory();
		CyTable table1 = factory.createTable("Table 1", "SUID", Long.class, true, true);
		CyTable table2 = factory.createTable("Table 2", "SUID", Long.class, true, true);
		table1.createListColumn("name", String.class, false);
		table1.createListColumn("real", String.class, false);
		table2.createListColumn("name", String.class, false);
		table2.addVirtualColumn("virtual", "real", table1, "SUID", false);
		
		List<String> list1 = new ArrayList<String>();
		list1.add("1");
		
		List<String> list2 = new ArrayList<String>();
		list2.add("2");
		
		CyRow row1 = table1.getRow(1L);
		row1.set("name", list1);
		
		CyRow row2 = table2.getRow(1L);
		row2.set("name", list2);
		
		row2.set("virtual", parseEquation("=SLIST($name)", table2));
		
		// Equation should be propagated to both tables
		Assert.assertNotNull(row1.getRaw("real"));
		Assert.assertNotNull(row2.getRaw("virtual"));
		
		// Equation should yield different values depending on context
		List<String> result1 = row1.getList("real", String.class);
		Assert.assertNotNull(result1);
		Assert.assertEquals(1, result1.size());
		Assert.assertEquals("1", result1.get(0));
		
		List<String> result2 = row2.getList("virtual", String.class);
		Assert.assertNotNull(result2);
		Assert.assertEquals(1, result2.size());
		Assert.assertEquals("2", result2.get(0));
		
		// Overwrite equation with normal attribute.  Both ends of
		// VirtualColumn should give the same answer.
		List<String> list3 = new ArrayList<String>();
		list3.add("3");
		row1.set("real", list3);
		
		List<String> result3a = row1.getList("real", String.class);
		Assert.assertNotNull(result3a);
		Assert.assertEquals(1, result3a.size());
		Assert.assertEquals("3", result3a.get(0));

		List<String> result3b = row2.getList("virtual", String.class);
		Assert.assertNotNull(result3b);
		Assert.assertEquals(1, result3b.size());
		Assert.assertEquals("3", result3b.get(0));
	}
}<commit_msg>Updated tests to check nested VirtualColumns<commit_after>package org.cytoscape.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import junit.framework.Assert;

import org.cytoscape.equations.Equation;
import org.cytoscape.equations.internal.EquationCompilerImpl;
import org.cytoscape.equations.internal.EquationParserImpl;
import org.junit.Before;
import org.junit.Test;

public class EquationTest {
	private TableTestSupport support;
	private EquationParserImpl parser;

	@Before
	public void setUp() {
		support = new TableTestSupport();
		parser = new EquationParserImpl();
	}

	Equation parseEquation(String equation, CyTable context) {
		Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
		for (CyColumn column : context.getColumns()) {
			typeMap.put(column.getName(), column.getType());
		}
		EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
		Assert.assertTrue(compiler.compile(equation, typeMap));
		return compiler.getEquation();
	}
	
	@Test
	public void testVirtualColumnEquation() {
		CyTableFactory factory = support.getTableFactory();
		CyTable table1 = factory.createTable("Table 1", "SUID", Long.class, true, true);
		CyTable table2 = factory.createTable("Table 2", "SUID", Long.class, true, true);
		CyTable table3 = factory.createTable("Table 3", "SUID", Long.class, true, true);
		table1.createColumn("name", String.class, false);
		table1.createColumn("real", String.class, false);
		table2.createColumn("name", String.class, false);
		table2.addVirtualColumn("virtual", "real", table1, "SUID", false);
		table3.createColumn("name", String.class, false);
		table3.addVirtualColumn("virtual2", "virtual", table2, "SUID", false);
		
		CyRow row1 = table1.getRow(1L);
		row1.set("name", "1");
		
		CyRow row2 = table2.getRow(1L);
		row2.set("name", "2");
		
		CyRow row3 = table3.getRow(1L);
		row3.set("name", "3");

		row3.set("virtual2", parseEquation("=$name", table3));
		
		// Equation should be propagated to all tables
		Assert.assertNotNull(row1.getRaw("real"));
		Assert.assertNotNull(row2.getRaw("virtual"));
		Assert.assertNotNull(row3.getRaw("virtual2"));
		
		// Equation should yield different values depending on context
		Assert.assertEquals("1", row1.get("real", String.class));
		Assert.assertEquals("2", row2.get("virtual", String.class));
		Assert.assertEquals("3", row3.get("virtual2", String.class));

		// Overwrite equation with normal attribute.  Both ends of
		// VirtualColumn should give the same answer.
		row1.set("real", "other");
		Assert.assertEquals("other", row1.get("real", String.class));
		Assert.assertEquals("other", row2.get("virtual", String.class));
		Assert.assertEquals("other", row3.get("virtual2", String.class));
	}
	
	@Test
	public void testVirtualColumnListEquation() {
		CyTableFactory factory = support.getTableFactory();
		CyTable table1 = factory.createTable("Table 1", "SUID", Long.class, true, true);
		CyTable table2 = factory.createTable("Table 2", "SUID", Long.class, true, true);
		CyTable table3 = factory.createTable("Table 3", "SUID", Long.class, true, true);
		table1.createListColumn("name", String.class, false);
		table1.createListColumn("real", String.class, false);
		table2.createListColumn("name", String.class, false);
		table2.addVirtualColumn("virtual", "real", table1, "SUID", false);
		table3.createListColumn("name", String.class, false);
		table3.addVirtualColumn("virtual2", "virtual", table2, "SUID", false);
		
		List<String> list1 = new ArrayList<String>();
		list1.add("1");
		
		List<String> list2 = new ArrayList<String>();
		list2.add("2");
		
		List<String> list3 = new ArrayList<String>();
		list3.add("3");

		CyRow row1 = table1.getRow(1L);
		row1.set("name", list1);
		
		CyRow row2 = table2.getRow(1L);
		row2.set("name", list2);
		
		CyRow row3 = table3.getRow(1L);
		row3.set("name", list3);

		row3.set("virtual2", parseEquation("=SLIST($name)", table3));
		
		// Equation should be propagated to all tables
		Assert.assertNotNull(row1.getRaw("real"));
		Assert.assertNotNull(row2.getRaw("virtual"));
		Assert.assertNotNull(row3.getRaw("virtual2"));
		
		// Equation should yield different values depending on context
		List<String> result1 = row1.getList("real", String.class);
		Assert.assertNotNull(result1);
		Assert.assertEquals(1, result1.size());
		Assert.assertEquals("1", result1.get(0));
		
		List<String> result2 = row2.getList("virtual", String.class);
		Assert.assertNotNull(result2);
		Assert.assertEquals(1, result2.size());
		Assert.assertEquals("2", result2.get(0));

		List<String> result3 = row3.getList("virtual2", String.class);
		Assert.assertNotNull(result3);
		Assert.assertEquals(1, result3.size());
		Assert.assertEquals("3", result3.get(0));

		// Overwrite equation with normal attribute.  Both ends of
		// VirtualColumn should give the same answer.
		List<String> other = new ArrayList<String>();
		other.add("other");
		row1.set("real", other);
		
		List<String> resultOther1 = row1.getList("real", String.class);
		Assert.assertNotNull(resultOther1);
		Assert.assertEquals(1, resultOther1.size());
		Assert.assertEquals("other", resultOther1.get(0));

		List<String> resultOther2 = row2.getList("virtual", String.class);
		Assert.assertNotNull(resultOther2);
		Assert.assertEquals(1, resultOther2.size());
		Assert.assertEquals("other", resultOther2.get(0));

		List<String> resultOther3 = row3.getList("virtual2", String.class);
		Assert.assertNotNull(resultOther3);
		Assert.assertEquals(1, resultOther3.size());
		Assert.assertEquals("other", resultOther3.get(0));
}
}
{'fraction_non_alphanumeric': 0.15536922921507224, 'fraction_numerical': 0.024446913829679767, 'mean_word_length': 5.317804722399489, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '533231', 'n_tokens_mistral': 3420, 'n_tokens_neox': 3057, 'n_words': 668}