<commit_before>/*****************************************************************************
 *  Limpet - the Lightweight InforMation ProcEssing Toolkit
 *  http://limpet.info
 *
 *  (C) 2015-2016, Deep Blue C Technologies Ltd
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the Eclipse Public License v1.0
 *  (http://www.eclipse.org/legal/epl-v10.html)
 *
 *  This library 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.
 *****************************************************************************/
package info.limpet.data2;

import info.limpet.IChangeListener;
import info.limpet.ICommand;
import info.limpet.IContext;
import info.limpet.IStoreItem;
import info.limpet.impl.MockContext;
import info.limpet.impl.NumberDocument;
import info.limpet.impl.SampleData;
import info.limpet.impl.StoreGroup;
import info.limpet.operations.arithmetic.simple.AddQuantityOperation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;

public class TestDynamic extends TestCase
{

	private IContext context = new MockContext();

	public void testSingleQuantityStats()
	{
		// get some data
		StoreGroup store = new SampleData().getData(10);

		// ok, let's try one that works
		List<IStoreItem> selection = new ArrayList<IStoreItem>();
		NumberDocument speedOne =  (NumberDocument) store.get(SampleData.SPEED_ONE);
		NumberDocument speedTwo =  (NumberDocument) store.get(SampleData.SPEED_TWO);
		selection.add(speedOne);
		selection.add(speedTwo);

		int storeSize = store.size();

		Collection<ICommand> actions = new AddQuantityOperation().actionsFor(
				selection, store, context);
		assertEquals("correct number of actions", 2, actions.size());
		Iterator<ICommand> addIter = actions.iterator();
		addIter.next();
		ICommand firstAction = addIter.next();
		assertEquals("correct action", "Add numeric values in provided series (interpolated)",
				firstAction.getName());

		// run the action
		firstAction.execute();

		// check we have new data
		assertEquals("new data created", storeSize + 1, store.size());

		// ok, get the new dataset
		NumberDocument resSeries = (NumberDocument) store
				.get("Sum of Speed One Time + Speed Two Time");
		assertNotNull(resSeries);

		// remember the units
    final String resUnits = resSeries.getUnits().toString();

		// ok, play about with a change
		final List<String> events = new ArrayList<String>();
		IChangeListener listener = new IChangeListener()
		{
			@Override
			public void dataChanged(IStoreItem subject)
			{
				events.add("changed!");
			}

      @Override
      public void metadataChanged(IStoreItem subject)
      {
        throw new RuntimeException("Not implemented");
      }

      @Override
      public void collectionDeleted(IStoreItem subject)
      {
        throw new RuntimeException("Not implemented");
      }
		};
		resSeries.addChangeListener(listener);
		assertEquals("empty at start", 0, events.size());

		// ok, now make a change in one of hte input collections
		speedOne.fireDataChanged();
		assertEquals("change received", 1, events.size());

		// check the units haven't changed
		assertEquals("units still valid", resUnits, resSeries.getUnits().toString());

		// ok, now make another change in one of hte input collections
		speedOne.fireDataChanged();
		assertEquals("second change received", 2, events.size());

		selection.clear();
		selection.add(speedTwo);
		selection.add(resSeries);

		// ok - now for a further dependent calculation
		actions = new AddQuantityOperation().actionsFor(selection, store, context);
		addIter = actions.iterator();
		addIter.next();
		firstAction = addIter.next();
		assertEquals("correct action", "Add numeric values in provided series (interpolated)",
				firstAction.getName());

		// ok, now create the new series
		firstAction.execute();

		// now check the output changed again
		events.clear();

		NumberDocument newResSeries = (NumberDocument) store
				.get("Sum of Speed Two Time + Speed One Time+Speed Two Time");
		assertNotNull("found new series", newResSeries);
		newResSeries.addChangeListener(listener);

		final String resUnits2 = newResSeries.getUnits().toString();

		// ok, fire a change in speed one
		speedOne.fireDataChanged();
		assertEquals("change received", 2, events.size());
<commit_msg>reflect changed dataset naming<commit_after>/*****************************************************************************
 *  Limpet - the Lightweight InforMation ProcEssing Toolkit
 *  http://limpet.info
 *
 *  (C) 2015-2016, Deep Blue C Technologies Ltd
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the Eclipse Public License v1.0
 *  (http://www.eclipse.org/legal/epl-v10.html)
 *
 *  This library 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.
 *****************************************************************************/
package info.limpet.data2;

import info.limpet.IChangeListener;
import info.limpet.ICommand;
import info.limpet.IContext;
import info.limpet.IStoreItem;
import info.limpet.impl.MockContext;
import info.limpet.impl.NumberDocument;
import info.limpet.impl.SampleData;
import info.limpet.impl.StoreGroup;
import info.limpet.operations.arithmetic.simple.AddQuantityOperation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;

public class TestDynamic extends TestCase
{

	private IContext context = new MockContext();

	public void testSingleQuantityStats()
	{
		// get some data
		StoreGroup store = new SampleData().getData(10);

		// ok, let's try one that works
		List<IStoreItem> selection = new ArrayList<IStoreItem>();
		NumberDocument speedOne =  (NumberDocument) store.get(SampleData.SPEED_ONE);
		NumberDocument speedTwo =  (NumberDocument) store.get(SampleData.SPEED_TWO);
		selection.add(speedOne);
		selection.add(speedTwo);

		int storeSize = store.size();

		Collection<ICommand> actions = new AddQuantityOperation().actionsFor(
				selection, store, context);
		assertEquals("correct number of actions", 2, actions.size());
		Iterator<ICommand> addIter = actions.iterator();
		addIter.next();
		ICommand firstAction = addIter.next();
		assertEquals("correct action", "Add numeric values in provided series (interpolated)",
				firstAction.getName());

		// run the action
		firstAction.execute();

		// check we have new data
		assertEquals("new data created", storeSize + 1, store.size());

		// ok, get the new dataset
		NumberDocument resSeries = (NumberDocument) store
				.get("Sum of Speed One Time + Speed Two Time");
		assertNotNull(resSeries);

		// remember the units
    final String resUnits = resSeries.getUnits().toString();

		// ok, play about with a change
		final List<String> events = new ArrayList<String>();
		IChangeListener listener = new IChangeListener()
		{
			@Override
			public void dataChanged(IStoreItem subject)
			{
				events.add("changed!");
			}

      @Override
      public void metadataChanged(IStoreItem subject)
      {
        throw new RuntimeException("Not implemented");
      }

      @Override
      public void collectionDeleted(IStoreItem subject)
      {
        throw new RuntimeException("Not implemented");
      }
		};
		resSeries.addChangeListener(listener);
		assertEquals("empty at start", 0, events.size());

		// ok, now make a change in one of hte input collections
		speedOne.fireDataChanged();
		assertEquals("change received", 1, events.size());

		// check the units haven't changed
		assertEquals("units still valid", resUnits, resSeries.getUnits().toString());

		// ok, now make another change in one of hte input collections
		speedOne.fireDataChanged();
		assertEquals("second change received", 2, events.size());

		selection.clear();
		selection.add(speedTwo);
		selection.add(resSeries);

		// ok - now for a further dependent calculation
		actions = new AddQuantityOperation().actionsFor(selection, store, context);
		addIter = actions.iterator();
		addIter.next();
		firstAction = addIter.next();
		assertEquals("correct action", "Add numeric values in provided series (interpolated)",
				firstAction.getName());

		// ok, now create the new series
		firstAction.execute();

		// now check the output changed again
		events.clear();

		NumberDocument newResSeries = (NumberDocument) store
				.get("Sum of Speed Two Time + Sum of Speed One Time + Speed Two Time");
		assertNotNull("found new series", newResSeries);
		newResSeries.addChangeListener(listener);

		final String resUnits2 = newResSeries.getUnits().toString();

		// ok, fire a change in speed one
		speedOne.fireDataChanged();
		assertEquals("change received", 2, events.size());

{'fraction_non_alphanumeric': 0.1385635359116022, 'fraction_numerical': 0.004861878453038674, 'mean_word_length': 4.381093935790726, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1083267', 'n_tokens_mistral': 2673, 'n_tokens_neox': 2417, 'n_words': 758}