From 0a1675f6a12ffbaa32812ade0afd2767288b16f7 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Tue, 26 Apr 2011 11:16:28 +0200
Subject: [PATCH] refactor tests a bit to remove code duplication

---
 tests/CMakeLists.txt         |  1 +
 tests/getlemmas.cpp          | 50 +++++++++---------------------
 tests/getorth.cpp            | 46 ++++++++--------------------
 tests/getsymbols.cpp         | 50 ++++++++++++++----------------
 tests/getsymbolsinrange.cpp  | 56 ++++++++++++----------------------
 tests/mark.cpp               | 58 +++++++++++------------------------
 tests/optest.cpp             | 21 +++++++++++++
 tests/optest.h               | 52 +++++++++++++++++++++++++++++++
 tests/positionpredicates.cpp | 59 ++++++++++++------------------------
 tests/relativeposition.cpp   | 58 ++++++++++++-----------------------
 10 files changed, 201 insertions(+), 250 deletions(-)
 create mode 100644 tests/optest.cpp
 create mode 100644 tests/optest.h

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d975c0c..6c5f662 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -19,6 +19,7 @@ include_directories( ${CMAKE_SOURCE_DIR} )
 add_definitions(-DLIBWCCL_TEST_DATA_DIR="${PROJECT_SOURCE_DIR}/")
 
 add_executable(tests
+	optest.cpp
 	conditional.cpp
 	constant.cpp
 	context.cpp
diff --git a/tests/getlemmas.cpp b/tests/getlemmas.cpp
index 568c687..a6a83f9 100644
--- a/tests/getlemmas.cpp
+++ b/tests/getlemmas.cpp
@@ -6,29 +6,20 @@
 #include <libwccl/ops/functions/constant.h>
 #include <libwccl/ops/functions/strset/getlemmas.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(get_lemmas)
 
-struct LemmasPredFix
+		struct LemmasPredFix : public Wccl::PositionFixture
 {
 	LemmasPredFix()
-		: s(boost::make_shared<Corpus2::Sentence>()),
+		: Wccl::PositionFixture(),
+		  s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(),
 		  cx(sc, boost::make_shared<Variables>()),
-		  pos_zero(0),
-		  pos_one(1),
-		  pos_minus_one(-1),
-		  nowhere(Position::Nowhere),
-		  begin(Position::Begin),
-		  end(Position::End),
-		  pos_zero_constant(new Constant<Position>(pos_zero)),
-		  pos_one_constant(new Constant<Position>(pos_one)),
-		  pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		  nowhere_constant(new Constant<Position>(nowhere)),
-		  begin_constant(new Constant<Position>(begin)),
-		  end_constant(new Constant<Position>(end)),
 		  empty_set(),
 		  first_lemmas(),
 		  second_lemmas()
@@ -62,18 +53,7 @@ struct LemmasPredFix
 	Corpus2::Tagset tagset;
 
 	FunExecContext cx;
-	Position pos_zero;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	Position begin;
-	Position end;
-	boost::shared_ptr<Function<Position> > pos_zero_constant;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > begin_constant;
-	boost::shared_ptr<Function<Position> > end_constant;
+
 	StrSet empty_set;
 	StrSet first_lemmas;
 	StrSet second_lemmas;
@@ -82,7 +62,7 @@ struct LemmasPredFix
 
 BOOST_FIXTURE_TEST_CASE(lemmas_nowhere, LemmasPredFix)
 {
-	GetLemmas lemmas(nowhere_constant);
+	GetLemmas lemmas(nowhere());
 	BOOST_CHECK(lemmas.apply(cx)->equals(empty_set));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(empty_set));
@@ -92,7 +72,7 @@ BOOST_FIXTURE_TEST_CASE(lemmas_nowhere, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_begin, LemmasPredFix)
 {
-	GetLemmas lemmas(begin_constant);
+	GetLemmas lemmas(begin());
 	BOOST_CHECK(lemmas.apply(cx)->equals(first_lemmas));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(first_lemmas));
@@ -102,7 +82,7 @@ BOOST_FIXTURE_TEST_CASE(lemmas_begin, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_end, LemmasPredFix)
 {
-	GetLemmas lemmas(end_constant);
+	GetLemmas lemmas(end());
 	BOOST_CHECK(lemmas.apply(cx)->equals(second_lemmas));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(second_lemmas));
@@ -112,7 +92,7 @@ BOOST_FIXTURE_TEST_CASE(lemmas_end, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_zero, LemmasPredFix)
 {
-	GetLemmas lemmas(pos_zero_constant);
+	GetLemmas lemmas(pos(0));
 	BOOST_CHECK(lemmas.apply(cx)->equals(first_lemmas));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(second_lemmas));
@@ -122,7 +102,7 @@ BOOST_FIXTURE_TEST_CASE(lemmas_zero, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_one, LemmasPredFix)
 {
-	GetLemmas lemmas(pos_one_constant);
+	GetLemmas lemmas(pos(1));
 	BOOST_CHECK(lemmas.apply(cx)->equals(second_lemmas));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(empty_set));
@@ -132,7 +112,7 @@ BOOST_FIXTURE_TEST_CASE(lemmas_one, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_minus_one, LemmasPredFix)
 {
-	GetLemmas lemmas(pos_minus_one_constant);
+	GetLemmas lemmas(pos(-1));
 	BOOST_CHECK(lemmas.apply(cx)->equals(empty_set));
 	sc.advance();
 	BOOST_CHECK(lemmas.apply(cx)->equals(first_lemmas));
@@ -145,15 +125,15 @@ BOOST_FIXTURE_TEST_CASE(lemmas_minus_one, LemmasPredFix)
 
 BOOST_FIXTURE_TEST_CASE(lemmas_to_string, LemmasPredFix)
 {
-	GetLemmas lemmas(begin_constant);
+	GetLemmas lemmas(begin());
 	BOOST_CHECK_EQUAL("base[begin]", lemmas.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(lemmas_to_raw_string, LemmasPredFix)
 {
-	GetLemmas lemmas(end_constant);
+	GetLemmas lemmas(end());
 	BOOST_CHECK_EQUAL("base[end]", lemmas.to_string(tagset));
-	GetLemmas lemmas2(pos_minus_one_constant);
+	GetLemmas lemmas2(pos(-1));
 	BOOST_CHECK_EQUAL("base[-1]", lemmas2.to_string(tagset));
 }
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/getorth.cpp b/tests/getorth.cpp
index 49e2b4a..3599cb3 100644
--- a/tests/getorth.cpp
+++ b/tests/getorth.cpp
@@ -6,29 +6,19 @@
 #include <libwccl/ops/functions/constant.h>
 #include <libwccl/ops/functions/strset/getorth.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(relative_position)
 
-struct OrthPredFix
+struct OrthPredFix: public Wccl::PositionFixture
 {
 	OrthPredFix()
 		: s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(),
 		  cx(sc, boost::make_shared<Variables>()),
-		  pos_zero(0),
-		  pos_one(1),
-		  pos_minus_one(-1),
-		  nowhere(Position::Nowhere),
-		  begin(Position::Begin),
-		  end(Position::End),
-		  pos_zero_constant(new Constant<Position>(pos_zero)),
-		  pos_one_constant(new Constant<Position>(pos_one)),
-		  pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		  nowhere_constant(new Constant<Position>(nowhere)),
-		  begin_constant(new Constant<Position>(begin)),
-		  end_constant(new Constant<Position>(end)),
 		  empty_set(),
 		  first_orth(),
 		  second_orth()
@@ -60,18 +50,6 @@ struct OrthPredFix
 	Corpus2::Tagset tagset;
 
 	FunExecContext cx;
-	Position pos_zero;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	Position begin;
-	Position end;
-	boost::shared_ptr<Function<Position> > pos_zero_constant;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > begin_constant;
-	boost::shared_ptr<Function<Position> > end_constant;
 	StrSet empty_set;
 	StrSet first_orth;
 	StrSet second_orth;
@@ -80,7 +58,7 @@ struct OrthPredFix
 
 BOOST_FIXTURE_TEST_CASE(orth_nowhere, OrthPredFix)
 {
-	GetOrth orth(nowhere_constant);
+	GetOrth orth(nowhere());
 	BOOST_CHECK(orth.apply(cx)->equals(empty_set));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(empty_set));
@@ -91,7 +69,7 @@ BOOST_FIXTURE_TEST_CASE(orth_nowhere, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_begin, OrthPredFix)
 {
-	GetOrth orth(begin_constant);
+	GetOrth orth(begin());
 	BOOST_CHECK(orth.apply(cx)->equals(first_orth));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(first_orth));
@@ -102,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(orth_begin, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_end, OrthPredFix)
 {
-	GetOrth orth(end_constant);
+	GetOrth orth(end());
 	BOOST_CHECK(orth.apply(cx)->equals(second_orth));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(second_orth));
@@ -113,7 +91,7 @@ BOOST_FIXTURE_TEST_CASE(orth_end, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_zero, OrthPredFix)
 {
-	GetOrth orth(pos_zero_constant);
+	GetOrth orth(pos(0));
 	BOOST_CHECK(orth.apply(cx)->equals(first_orth));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(second_orth));
@@ -124,7 +102,7 @@ BOOST_FIXTURE_TEST_CASE(orth_zero, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_one, OrthPredFix)
 {
-	GetOrth orth(pos_one_constant);
+	GetOrth orth(pos(1));
 	BOOST_CHECK(orth.apply(cx)->equals(second_orth));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(empty_set));
@@ -135,7 +113,7 @@ BOOST_FIXTURE_TEST_CASE(orth_one, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_minus_one, OrthPredFix)
 {
-	GetOrth orth(pos_minus_one_constant);
+	GetOrth orth(pos(-1));
 	BOOST_CHECK(orth.apply(cx)->equals(empty_set));
 	sc.advance();
 	BOOST_CHECK(orth.apply(cx)->equals(first_orth));
@@ -149,15 +127,15 @@ BOOST_FIXTURE_TEST_CASE(orth_minus_one, OrthPredFix)
 
 BOOST_FIXTURE_TEST_CASE(orth_to_string, OrthPredFix)
 {
-	GetOrth orth(begin_constant);
+	GetOrth orth(begin());
 	BOOST_CHECK_EQUAL("orth[begin]", orth.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(orth_to_raw_string, OrthPredFix)
 {
-	GetOrth orth(end_constant);
+	GetOrth orth(end());
 	BOOST_CHECK_EQUAL("orth[end]", orth.to_string(tagset));
-	GetOrth orth2(pos_minus_one_constant);
+	GetOrth orth2(pos(-1));
 	BOOST_CHECK_EQUAL("orth[-1]", orth2.to_string(tagset));
 }
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/getsymbols.cpp b/tests/getsymbols.cpp
index effd28d..f44149f 100644
--- a/tests/getsymbols.cpp
+++ b/tests/getsymbols.cpp
@@ -8,21 +8,20 @@
 #include <libwccl/ops/functions/tset/getsymbols.h>
 #include <libwccl/ops/functions/tset/getwordclass.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(get_symbols_op)
 
-struct SymbolsFix
+struct SymbolsFix : public Wccl::PositionFixture
 {
 	SymbolsFix()
-		: s(boost::make_shared<Corpus2::Sentence>()),
+		: Wccl::PositionFixture(),
+		  s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(Corpus2::get_named_tagset("kipi")),
-		  cx(sc, boost::make_shared<Variables>()),
-		  pos_zero(0),
-		  nowhere(Position::Nowhere),
-		  pos_zero_constant(new Constant<Position>(pos_zero)),
-		  nowhere_constant(new Constant<Position>(nowhere))
+		  cx(sc, boost::make_shared<Variables>())
 	{
 		Corpus2::Token* the_token = new Corpus2::Token(
 				"One",
@@ -45,7 +44,7 @@ struct SymbolsFix
 		gnd = tagset.parse_symbol("gnd");
 		nmb = tagset.parse_symbol("nmb");
 		vcl = tagset.parse_symbol("vcl");
-		pos.set_pos(-1); //todo
+		tag_pos.set_pos(-1); //todo
 	}
 
 	boost::shared_ptr<Corpus2::Sentence> s;
@@ -53,37 +52,32 @@ struct SymbolsFix
 	const Corpus2::Tagset& tagset;
 
 	FunExecContext cx;
-	Position pos_zero;
-	Position nowhere;
-	boost::shared_ptr<Function<Position> > pos_zero_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
 	TSet empty;
 	Corpus2::Tag gnd;
 	Corpus2::Tag nmb;
 	Corpus2::Tag vcl;
-	Corpus2::Tag pos;
+	Corpus2::Tag tag_pos;
 };
 
 BOOST_FIXTURE_TEST_CASE(symbols_nowhere, SymbolsFix)
 {
-	GetSymbols symbols(gnd, nowhere_constant);
+	GetSymbols symbols(gnd, nowhere());
 	BOOST_CHECK(symbols.apply(cx)->equals(empty));
-	GetSymbols s2(nmb, nowhere_constant);
+	GetSymbols s2(nmb, nowhere());
 	BOOST_CHECK(s2.apply(cx)->equals(empty));
-	GetSymbols s3(pos, nowhere_constant);
+	GetSymbols s3(tag_pos, nowhere());
 	BOOST_CHECK(s3.apply(cx)->equals(empty));
 }
 
 BOOST_FIXTURE_TEST_CASE(symbols_outside, SymbolsFix)
 {
-	GetSymbols symbols(gnd, boost::shared_ptr<Function<Position> >(
-			new Constant<Position>(Position(-1))));
+	GetSymbols symbols(gnd, pos(-1));
 	BOOST_CHECK(symbols.apply(cx)->equals(empty));
 }
 
 BOOST_FIXTURE_TEST_CASE(get_gnd, SymbolsFix)
 {
-	GetSymbols symbols(gnd, pos_zero_constant);
+	GetSymbols symbols(gnd, pos(0));
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{m1,m2}");
 	sc.advance();
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{f}");
@@ -93,7 +87,7 @@ BOOST_FIXTURE_TEST_CASE(get_gnd, SymbolsFix)
 
 BOOST_FIXTURE_TEST_CASE(get_nmb, SymbolsFix)
 {
-	GetSymbols symbols(nmb, pos_zero_constant);
+	GetSymbols symbols(nmb, pos(0));
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{sg}");
 	sc.advance();
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{pl}");
@@ -103,7 +97,7 @@ BOOST_FIXTURE_TEST_CASE(get_nmb, SymbolsFix)
 
 BOOST_FIXTURE_TEST_CASE(get_vcl, SymbolsFix)
 {
-	GetSymbols symbols(vcl, pos_zero_constant);
+	GetSymbols symbols(vcl, pos(0));
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{}");
 	sc.advance();
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{wok}");
@@ -111,9 +105,9 @@ BOOST_FIXTURE_TEST_CASE(get_vcl, SymbolsFix)
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{}");
 }
 
-BOOST_FIXTURE_TEST_CASE(get_pos, SymbolsFix)
+BOOST_FIXTURE_TEST_CASE(get_tag_pos, SymbolsFix)
 {
-	GetSymbols symbols(pos, pos_zero_constant);
+	GetSymbols symbols(tag_pos, pos(0));
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{subst}");
 	sc.advance();
 	BOOST_CHECK_EQUAL(symbols.apply(cx)->to_string(tagset), "{adja,prep,subst}");
@@ -123,13 +117,13 @@ BOOST_FIXTURE_TEST_CASE(get_pos, SymbolsFix)
 
 BOOST_FIXTURE_TEST_CASE(get_symbols_to_string, SymbolsFix)
 {
-	GetSymbols symbols(nmb, pos_zero_constant);
+	GetSymbols symbols(nmb, pos(0));
 	BOOST_CHECK_EQUAL("nmb[0]", symbols.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(get_symbols_to_raw_string, SymbolsFix)
 {
-	GetSymbols symbols(nmb, pos_zero_constant);
+	GetSymbols symbols(nmb, pos(0));
 	std::string expected = nmb.raw_dump() + "[0]";
 	BOOST_CHECK_EQUAL(expected, symbols.to_raw_string());
 }
@@ -140,7 +134,7 @@ BOOST_FIXTURE_TEST_CASE(get_symbols_to_raw_string, SymbolsFix)
 
 BOOST_FIXTURE_TEST_CASE(get_word_class, SymbolsFix)
 {
-	GetWordClass wclass(pos_zero_constant);
+	GetWordClass wclass(pos(0));
 	BOOST_CHECK_EQUAL(wclass.apply(cx)->to_string(tagset), "{subst}");
 	sc.advance();
 	BOOST_CHECK_EQUAL(wclass.apply(cx)->to_string(tagset), "{adja,prep,subst}");
@@ -150,13 +144,13 @@ BOOST_FIXTURE_TEST_CASE(get_word_class, SymbolsFix)
 
 BOOST_FIXTURE_TEST_CASE(get_word_class_to_string, SymbolsFix)
 {
-	GetWordClass wclass(pos_zero_constant);
+	GetWordClass wclass(pos(0));
 	BOOST_CHECK_EQUAL("class[0]", wclass.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(get_word_class_to_raw_string, SymbolsFix)
 {
-	GetWordClass wclass(pos_zero_constant);
+	GetWordClass wclass(pos(0));
 	BOOST_CHECK_EQUAL("class[0]", wclass.to_raw_string());
 }
 
diff --git a/tests/getsymbolsinrange.cpp b/tests/getsymbolsinrange.cpp
index 521ba4c..b5b9cf0 100644
--- a/tests/getsymbolsinrange.cpp
+++ b/tests/getsymbolsinrange.cpp
@@ -8,27 +8,20 @@
 #include <libwccl/ops/functions/tset/getsymbols.h>
 #include <libwccl/ops/functions/tset/getsymbolsinrange.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(get_symbols_in_range_op)
 
-struct SymbolsInRangeFix
+struct SymbolsInRangeFix : public Wccl::PositionFixture
 {
 	SymbolsInRangeFix()
-		: s(boost::make_shared<Corpus2::Sentence>()),
+		: Wccl::PositionFixture(2),
+		  s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(Corpus2::get_named_tagset("kipi")),
-		  cx(sc, boost::make_shared<Variables>()),
-		  pos_zero(0),
-		  pos_one(1),
-		  pos_minus_one(-1),
-		  nowhere(Position::Nowhere),
-		  pos_zero_constant(new Constant<Position>(pos_zero)),
-		  pos_one_constant(new Constant<Position>(pos_one)),
-		  pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		  nowhere_constant(new Constant<Position>(nowhere)),
-		  pos_plus_2_constant(new Constant<Position>(Position(2))),
-		  pos_minus_2_constant(new Constant<Position>(Position(-2)))
+		  cx(sc, boost::make_shared<Variables>())
 	{
 		Corpus2::Token* the_token = new Corpus2::Token(
 				"One",
@@ -58,32 +51,23 @@ struct SymbolsInRangeFix
 	const Corpus2::Tagset& tagset;
 
 	FunExecContext cx;
-	Position pos_zero;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	boost::shared_ptr<Function<Position> > pos_zero_constant;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > pos_plus_2_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_2_constant;
+
 	TSet empty;
 	Corpus2::Tag gnd;
 	Corpus2::Tag nmb;
 	Corpus2::Tag vcl;
-	Corpus2::Tag pos;
+	Corpus2::Tag tagpos;
 };
 
 BOOST_FIXTURE_TEST_CASE(range_nowhere, SymbolsInRangeFix)
 {
 	for(int i = 0; i < 3; i++)
 	{
-		GetSymbolsInRange range(gnd, nowhere_constant, pos_zero_constant);
+		GetSymbolsInRange range(gnd, nowhere(), pos(0));
 		BOOST_CHECK(range.apply(cx)->equals(empty));
-		GetSymbolsInRange r2(gnd, pos_zero_constant, nowhere_constant);
+		GetSymbolsInRange r2(gnd, pos(0), nowhere());
 		BOOST_CHECK(r2.apply(cx)->equals(empty));
-		GetSymbolsInRange r3(gnd, nowhere_constant, nowhere_constant);
+		GetSymbolsInRange r3(gnd, nowhere(), nowhere());
 		BOOST_CHECK(r3.apply(cx)->equals(empty));
 		sc.advance();
 	}
@@ -91,22 +75,22 @@ BOOST_FIXTURE_TEST_CASE(range_nowhere, SymbolsInRangeFix)
 
 BOOST_FIXTURE_TEST_CASE(range_outside, SymbolsInRangeFix)
 {
-	GetSymbolsInRange range(gnd, pos_minus_2_constant, pos_minus_one_constant);
+	GetSymbolsInRange range(gnd, pos(-2), pos(-1));
 	BOOST_CHECK(range.apply(cx)->equals(empty));
 	sc.advance();
-	GetSymbolsInRange r2(gnd, pos_one_constant, pos_plus_2_constant);
+	GetSymbolsInRange r2(gnd, pos(1), pos(2));
 	BOOST_CHECK(r2.apply(cx)->equals(empty));
 }
 
 BOOST_FIXTURE_TEST_CASE(range_valid_including_trimmed, SymbolsInRangeFix)
 {
-	GetSymbolsInRange range(gnd, pos_minus_2_constant, pos_zero_constant);
+	GetSymbolsInRange range(gnd, pos(-2), pos(0));
 	BOOST_CHECK_EQUAL("{m1,m2}", range.apply(cx)->to_string(tagset));
-	GetSymbolsInRange r2(gnd, pos_minus_one_constant, pos_zero_constant);
+	GetSymbolsInRange r2(gnd, pos(-1), pos(0));
 	BOOST_CHECK_EQUAL("{m1,m2}", r2.apply(cx)->to_string(tagset));
-	GetSymbolsInRange r3(gnd, pos_one_constant, pos_plus_2_constant);
+	GetSymbolsInRange r3(gnd, pos(1), pos(2));
 	BOOST_CHECK_EQUAL("{f}", r3.apply(cx)->to_string(tagset));
-	GetSymbolsInRange r4(gnd, pos_zero_constant, pos_plus_2_constant);
+	GetSymbolsInRange r4(gnd, pos(0), pos(2));
 	BOOST_CHECK_EQUAL("{m1,m2,f}", r4.apply(cx)->to_string(tagset));
 	sc.advance();
 	BOOST_CHECK_EQUAL("{m1,m2,f}", range.apply(cx)->to_string(tagset));
@@ -122,7 +106,7 @@ BOOST_FIXTURE_TEST_CASE(range_valid_including_trimmed, SymbolsInRangeFix)
 
 BOOST_FIXTURE_TEST_CASE(range_same_token, SymbolsInRangeFix)
 {
-	GetSymbolsInRange range(gnd, pos_zero_constant, pos_zero_constant);
+	GetSymbolsInRange range(gnd, pos(0), pos(0));
 	BOOST_CHECK_EQUAL("{m1,m2}", range.apply(cx)->to_string(tagset));
 	sc.advance();
 	BOOST_CHECK_EQUAL("{f}", range.apply(cx)->to_string(tagset));
@@ -133,13 +117,13 @@ BOOST_FIXTURE_TEST_CASE(range_same_token, SymbolsInRangeFix)
 
 BOOST_FIXTURE_TEST_CASE(range_to_string, SymbolsInRangeFix)
 {
-	GetSymbolsInRange range(gnd, pos_zero_constant, pos_plus_2_constant);
+	GetSymbolsInRange range(gnd, pos(0), pos(2));
 	BOOST_CHECK_EQUAL("range(gnd, 0, 2)", range.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(range_to_raw_string, SymbolsInRangeFix)
 {
-	GetSymbolsInRange range(gnd, pos_zero_constant, pos_plus_2_constant);
+	GetSymbolsInRange range(gnd, pos(0), pos(2));
 	std::string expected = "range(" + gnd.raw_dump() + ", 0, 2)";
 	BOOST_CHECK_EQUAL(expected, range.to_raw_string());
 }
diff --git a/tests/mark.cpp b/tests/mark.cpp
index 23e52b7..afec4ae 100644
--- a/tests/mark.cpp
+++ b/tests/mark.cpp
@@ -5,28 +5,19 @@
 
 #include <libwccl/ops/tagactions/mark.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(mark)
 
-struct MarkFix
+struct MarkFix : public Wccl::PositionFixture
 {
 	MarkFix()
-		: as(boost::make_shared<Corpus2::AnnotatedSentence>()),
+		: Wccl::PositionFixture(),
+		as(boost::make_shared<Corpus2::AnnotatedSentence>()),
 		sc(as),
-		cx(sc, boost::make_shared<Variables>()),
-		pos_zero(0),
-		pos_one(1),
-		pos_minus_one(-1),
-		nowhere(Position::Nowhere),
-		begin(Position::Begin),
-		end(Position::End),
-		pos_zero_constant(new Constant<Position>(pos_zero)),
-		pos_one_constant(new Constant<Position>(pos_one)),
-		pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		nowhere_constant(new Constant<Position>(nowhere)),
-		begin_constant(new Constant<Position>(begin)),
-		end_constant(new Constant<Position>(end))
+		cx(sc, boost::make_shared<Variables>())
 	{
 		as->append(new Corpus2::Token(UnicodeString::fromUTF8("t1"), PwrNlp::Whitespace::Newline));
 		as->append(new Corpus2::Token(UnicodeString::fromUTF8("t2"), PwrNlp::Whitespace::Newline));
@@ -43,25 +34,12 @@ struct MarkFix
 	SentenceContext sc;
 	Corpus2::Tagset tagset;
 	ActionExecContext cx;
-
-	Position pos_zero;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	Position begin;
-	Position end;
-	boost::shared_ptr<Function<Position> > pos_zero_constant;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > begin_constant;
-	boost::shared_ptr<Function<Position> > end_constant;
 };
 
 BOOST_FIXTURE_TEST_CASE(mark_empty, MarkFix)
 {
 	boost::shared_ptr<Corpus2::AnnotatedSentence> as_clone = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(as->clone_shared());
-	Mark mark(pos_minus_one_constant, pos_minus_one_constant, "ch1");
+	Mark mark(pos(-1), pos(-1), "ch1");
 	BOOST_CHECK(!mark.execute(cx));
 	//BOOST_CHECK((*as) == (*as_clone));
 	BOOST_CHECK_EQUAL(as->get_channel("ch1").dump_alpha(), "__aA_");
@@ -71,7 +49,7 @@ BOOST_FIXTURE_TEST_CASE(mark_already_there, MarkFix)
 {
 	boost::shared_ptr<Corpus2::AnnotatedSentence> as_clone = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(as->clone_shared());
 	sc.set_position(1);
-	Mark mark(begin_constant, pos_one_constant, "ch1");
+	Mark mark(begin(), pos(1), "ch1");
 	BOOST_CHECK(!mark.execute(cx));
 	BOOST_CHECK_EQUAL(as->get_channel("ch1").dump_alpha(), "__aA_");
 }
@@ -80,7 +58,7 @@ BOOST_FIXTURE_TEST_CASE(mark_begin, MarkFix)
 {
 	boost::shared_ptr<Corpus2::AnnotatedSentence> as_clone = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(as->clone_shared());
 	sc.set_position(1);
-	Mark mark(begin_constant, pos_minus_one_constant, "ch1");
+	Mark mark(begin(), pos(-1), "ch1");
 	BOOST_CHECK(mark.execute(cx));
 	BOOST_CHECK_EQUAL(as->get_channel("ch1").dump_alpha(), "B_aA_");
 }
@@ -89,7 +67,7 @@ BOOST_FIXTURE_TEST_CASE(mark_begin_head0, MarkFix)
 {
 	boost::shared_ptr<Corpus2::AnnotatedSentence> as_clone = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(as->clone_shared());
 	sc.set_position(0);
-	Mark mark(begin_constant, pos_one_constant, pos_zero_constant, "ch1");
+	Mark mark(begin(), pos(1), pos(0), "ch1");
 	BOOST_CHECK(mark.execute(cx));
 	BOOST_CHECK_EQUAL(as->get_channel("ch1").dump_alpha(), "BbaA_");
 }
@@ -98,7 +76,7 @@ BOOST_FIXTURE_TEST_CASE(mark_begin_head1, MarkFix)
 {
 	boost::shared_ptr<Corpus2::AnnotatedSentence> as_clone = boost::dynamic_pointer_cast<Corpus2::AnnotatedSentence>(as->clone_shared());
 	sc.set_position(0);
-	Mark mark(begin_constant, pos_one_constant, pos_one_constant, "ch1");
+	Mark mark(begin(), pos(1), pos(1), "ch1");
 	BOOST_CHECK(mark.execute(cx));
 	BOOST_CHECK_EQUAL(as->get_channel("ch1").dump_alpha(), "bBaA_");
 }
@@ -106,7 +84,7 @@ BOOST_FIXTURE_TEST_CASE(mark_begin_head1, MarkFix)
 BOOST_FIXTURE_TEST_CASE(mark_other, MarkFix)
 {
 	sc.set_position(1);
-	Mark mark(begin_constant, pos_one_constant, begin_constant, "ch2");
+	Mark mark(begin(), pos(1), begin(), "ch2");
 	BOOST_CHECK(mark.execute(cx));
 	BOOST_CHECK_EQUAL(as->get_channel("ch2").dump_alpha(), "Aaa__");
 }
@@ -116,21 +94,21 @@ BOOST_FIXTURE_TEST_CASE(mark_other, MarkFix)
 
 BOOST_FIXTURE_TEST_CASE(mark_to_string, MarkFix)
 {
-	Mark mark(begin_constant, end_constant, "ch");
+	Mark mark(begin(), end(), "ch");
 	BOOST_CHECK_EQUAL("mark(begin, end, \"ch\")", mark.to_string(tagset));
-	Mark mark2(begin_constant, pos_one_constant, "ch2");
+	Mark mark2(begin(), pos(1), "ch2");
 	BOOST_CHECK_EQUAL("mark(begin, 1, \"ch2\")", mark2.to_string(tagset));
-	Mark mark3(pos_minus_one_constant, end_constant, "ch3");
+	Mark mark3(pos(-1), end(), "ch3");
 	BOOST_CHECK_EQUAL("mark(-1, end, \"ch3\")", mark3.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(mark_to_string_head, MarkFix)
 	{
-	Mark mark(begin_constant, end_constant, pos_one_constant, "ch");
+	Mark mark(begin(), end(), pos(1), "ch");
 	BOOST_CHECK_EQUAL("mark(begin, end, 1, \"ch\")", mark.to_string(tagset));
-	Mark mark2(begin_constant, pos_one_constant, pos_zero_constant, "ch2");
+	Mark mark2(begin(), pos(1), pos(0), "ch2");
 	BOOST_CHECK_EQUAL("mark(begin, 1, 0, \"ch2\")", mark2.to_string(tagset));
-	Mark mark3(pos_minus_one_constant, end_constant, end_constant, "ch3");
+	Mark mark3(pos(-1), end(), end(), "ch3");
 	BOOST_CHECK_EQUAL("mark(-1, end, end, \"ch3\")", mark3.to_string(tagset));
 }
 
diff --git a/tests/optest.cpp b/tests/optest.cpp
new file mode 100644
index 0000000..a0be389
--- /dev/null
+++ b/tests/optest.cpp
@@ -0,0 +1,21 @@
+#include "optest.h"
+
+namespace Wccl {
+
+PositionFixture::PositionFixture(int max_offset /*=1*/)
+	: max_offset_(max_offset)
+{
+	assert(max_offset >= 0);
+	positions_.push_back(Position(Position::Begin));
+	positions_.push_back(Position(Position::End));
+	positions_.push_back(Position(Position::Nowhere));
+	for (int i = -max_offset; i <= max_offset; ++i) {
+		positions_.push_back(Position(i));
+	}
+	for (size_t i = 0; i < positions_.size(); ++i) {
+		constants_.push_back(
+			boost::make_shared< Constant<Position> >(positions_[i]));
+	}
+}
+
+} /* end ns Wccl */
diff --git a/tests/optest.h b/tests/optest.h
new file mode 100644
index 0000000..b9fa586
--- /dev/null
+++ b/tests/optest.h
@@ -0,0 +1,52 @@
+#ifndef LIBWCCL_TESTS_OPTEST_H
+#define LIBWCCL_TESTS_OPTEST_H
+
+#include <libwccl/ops/functions/constant.h>
+#include <libwccl/ops/function.h>
+#include <libwccl/values/position.h>
+
+
+namespace Wccl {
+
+class PositionFixture
+{
+public:
+	PositionFixture(int max_offset = 1);
+
+	int max_offset() { return max_offset(); }
+
+	Position begin_value() { return positions_[0]; }
+	Position end_value() { return positions_[1]; }
+	Position nowhere_value() { return positions_[2]; }
+	Position pos_value(int offset) {
+		return positions_[get_idx(offset)];
+	}
+
+	boost::shared_ptr< Wccl::Function<Position> > begin() { return constants_[0]; }
+	boost::shared_ptr< Wccl::Function<Position> > end() { return constants_[1]; }
+	boost::shared_ptr< Wccl::Function<Position> > nowhere() { return constants_[2]; }
+	boost::shared_ptr< Wccl::Function<Position> > pos(int offset) {
+		return constants_[get_idx(offset)];
+	}
+
+protected:
+
+private:
+	int get_idx(int offset) {
+		assert(offset <= max_offset_);
+		assert(offset >= -max_offset_);
+		int idx = offset + max_offset_ + 3;
+		assert(idx >= 0);
+		assert(static_cast<size_t>(idx) < positions_.size());
+		return idx;
+	}
+
+	int max_offset_;
+	std::vector<Position> positions_;
+	std::vector< boost::shared_ptr< Wccl::Function<Position> > > constants_;
+};
+
+
+} /* end ns Wccl */
+
+#endif // LIBWCCL_TESTS_OPTEST_H
diff --git a/tests/positionpredicates.cpp b/tests/positionpredicates.cpp
index 7ff1a4a..8f631ef 100644
--- a/tests/positionpredicates.cpp
+++ b/tests/positionpredicates.cpp
@@ -7,27 +7,20 @@
 #include <libwccl/ops/functions/bool/predicates/isinside.h>
 #include <libwccl/ops/functions/bool/predicates/isoutside.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(position_predicates)
 
-struct PosPredFix
+		struct PosPredFix : public Wccl::PositionFixture
 {
 	PosPredFix()
-		: s(boost::make_shared<Corpus2::Sentence>()),
+		: Wccl::PositionFixture(),
+		  s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(),
-		  cx(sc, boost::make_shared<Variables>()),
-		  pos_one(1),
-		  pos_minus_one(-1),
-		  nowhere(Position::Nowhere),
-		  begin(Position::Begin),
-		  end(Position::End),
-		  pos_one_constant(new Constant<Position>(pos_one)),
-		  pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		  nowhere_constant(new Constant<Position>(nowhere)),
-		  begin_constant(new Constant<Position>(begin)),
-		  end_constant(new Constant<Position>(end))
+		  cx(sc, boost::make_shared<Variables>())
 	{
 		Corpus2::Token* the_token = new Corpus2::Token("ZZ", PwrNlp::Whitespace::ManySpaces);
 		Corpus2::Tag t1(Corpus2::mask_t(0));
@@ -42,24 +35,12 @@ struct PosPredFix
 	boost::shared_ptr<Corpus2::Sentence> s;
 	SentenceContext sc;
 	Corpus2::Tagset tagset;
-
 	FunExecContext cx;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	Position begin;
-	Position end;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > begin_constant;
-	boost::shared_ptr<Function<Position> > end_constant;
-
 };
 
 BOOST_FIXTURE_TEST_CASE(is_inside_1, PosPredFix)
 {
-	IsInside is_inside(pos_one_constant);
+	IsInside is_inside(pos(1));
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(!is_inside.apply(cx)->get_value());
@@ -67,7 +48,7 @@ BOOST_FIXTURE_TEST_CASE(is_inside_1, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_inside_minus1, PosPredFix)
 {
-	IsInside is_inside(pos_minus_one_constant);
+	IsInside is_inside(pos(-1));
 	BOOST_CHECK(!is_inside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
@@ -75,7 +56,7 @@ BOOST_FIXTURE_TEST_CASE(is_inside_minus1, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_inside_nowhere, PosPredFix)
 {
-	IsInside is_inside(nowhere_constant);
+	IsInside is_inside(nowhere());
 	BOOST_CHECK(!is_inside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(!is_inside.apply(cx)->get_value());
@@ -83,7 +64,7 @@ BOOST_FIXTURE_TEST_CASE(is_inside_nowhere, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_inside_begin, PosPredFix)
 {
-	IsInside is_inside(begin_constant);
+	IsInside is_inside(begin());
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
@@ -91,7 +72,7 @@ BOOST_FIXTURE_TEST_CASE(is_inside_begin, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_inside_end, PosPredFix)
 {
-	IsInside is_inside(end_constant);
+	IsInside is_inside(end());
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(is_inside.apply(cx)->get_value());
@@ -99,7 +80,7 @@ BOOST_FIXTURE_TEST_CASE(is_inside_end, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_outside_1, PosPredFix)
 {
-	IsOutside is_outside(pos_one_constant);
+	IsOutside is_outside(pos(1));
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(is_outside.apply(cx)->get_value());
@@ -107,7 +88,7 @@ BOOST_FIXTURE_TEST_CASE(is_outside_1, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_outside_minus1, PosPredFix)
 {
-	IsOutside is_outside(pos_minus_one_constant);
+	IsOutside is_outside(pos(-1));
 	BOOST_CHECK(is_outside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
@@ -115,7 +96,7 @@ BOOST_FIXTURE_TEST_CASE(is_outside_minus1, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_outside_nowhere, PosPredFix)
 {
-	IsOutside is_outside(nowhere_constant);
+	IsOutside is_outside(nowhere());
 	BOOST_CHECK(is_outside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(is_outside.apply(cx)->get_value());
@@ -123,7 +104,7 @@ BOOST_FIXTURE_TEST_CASE(is_outside_nowhere, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_outside_begin, PosPredFix)
 {
-	IsOutside is_outside(begin_constant);
+	IsOutside is_outside(begin());
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
@@ -131,7 +112,7 @@ BOOST_FIXTURE_TEST_CASE(is_outside_begin, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_outside_end, PosPredFix)
 {
-	IsOutside is_outside(end_constant);
+	IsOutside is_outside(end());
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
 	sc.advance();
 	BOOST_CHECK(!is_outside.apply(cx)->get_value());
@@ -140,25 +121,25 @@ BOOST_FIXTURE_TEST_CASE(is_outside_end, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(is_inside_to_string, PosPredFix)
 {
-	IsInside is_inside(end_constant);
+	IsInside is_inside(end());
 	BOOST_CHECK_EQUAL("inside(end)", is_inside.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(is_inside_to_raw_string, PosPredFix)
 {
-	IsInside is_inside(end_constant);
+	IsInside is_inside(end());
 	BOOST_CHECK_EQUAL("inside(end)", is_inside.to_raw_string());
 }
 
 BOOST_FIXTURE_TEST_CASE(is_outside_to_string, PosPredFix)
 {
-	IsOutside is_outside(begin_constant);
+	IsOutside is_outside(begin());
 	BOOST_CHECK_EQUAL("outside(begin)", is_outside.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(is_outside_to_raw_string, PosPredFix)
 {
-	IsOutside is_outside(nowhere_constant);
+	IsOutside is_outside(nowhere());
 	BOOST_CHECK_EQUAL("outside(nowhere)", is_outside.to_raw_string());
 }
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/relativeposition.cpp b/tests/relativeposition.cpp
index 87dc70e..0158d1e 100644
--- a/tests/relativeposition.cpp
+++ b/tests/relativeposition.cpp
@@ -6,27 +6,20 @@
 #include <libwccl/ops/functions/constant.h>
 #include <libwccl/ops/functions/position/relativeposition.h>
 
+#include "optest.h"
+
 using namespace Wccl;
 
 BOOST_AUTO_TEST_SUITE(relative_position)
 
-struct PosPredFix
+struct PosPredFix : public Wccl::PositionFixture
 {
 	PosPredFix()
-		: s(boost::make_shared<Corpus2::Sentence>()),
+		: Wccl::PositionFixture(2),
+		  s(boost::make_shared<Corpus2::Sentence>()),
 		  sc(s),
 		  tagset(),
-		  cx(sc, boost::make_shared<Variables>()),
-		  pos_one(1),
-		  pos_minus_one(-1),
-		  nowhere(Position::Nowhere),
-		  begin(Position::Begin),
-		  end(Position::End),
-		  pos_one_constant(new Constant<Position>(pos_one)),
-		  pos_minus_one_constant(new Constant<Position>(pos_minus_one)),
-		  nowhere_constant(new Constant<Position>(nowhere)),
-		  begin_constant(new Constant<Position>(begin)),
-		  end_constant(new Constant<Position>(end))
+		  cx(sc, boost::make_shared<Variables>())
 	{
 		Corpus2::Token* the_token = new Corpus2::Token("ZZ", PwrNlp::Whitespace::ManySpaces);
 		Corpus2::Tag t1(Corpus2::mask_t(0));
@@ -43,16 +36,6 @@ struct PosPredFix
 	Corpus2::Tagset tagset;
 
 	FunExecContext cx;
-	Position pos_one;
-	Position pos_minus_one;
-	Position nowhere;
-	Position begin;
-	Position end;
-	boost::shared_ptr<Function<Position> > pos_one_constant;
-	boost::shared_ptr<Function<Position> > pos_minus_one_constant;
-	boost::shared_ptr<Function<Position> > nowhere_constant;
-	boost::shared_ptr<Function<Position> > begin_constant;
-	boost::shared_ptr<Function<Position> > end_constant;
 
 };
 
@@ -60,7 +43,7 @@ BOOST_FIXTURE_TEST_CASE(rel_nowhere, PosPredFix)
 {
 	for(int offset = -2; offset < 3; offset++)
 	{
-		RelativePosition relpos(nowhere_constant, offset);
+		RelativePosition relpos(nowhere(), offset);
 		BOOST_CHECK_EQUAL(
 			Position::Nowhere,
 			relpos.apply(cx)->get_value());
@@ -80,7 +63,7 @@ BOOST_FIXTURE_TEST_CASE(rel_begin, PosPredFix)
 {
 	for(int offset = -2; offset < 3; offset++)
 	{
-		RelativePosition relpos(begin_constant, offset);
+		RelativePosition relpos(begin(), offset);
 		BOOST_CHECK_EQUAL(
 			offset,
 			cx.sentence_context().get_abs_position(*relpos.apply(cx)));
@@ -100,7 +83,7 @@ BOOST_FIXTURE_TEST_CASE(rel_end, PosPredFix)
 {
 	for(int i = -2; i < 3; i++)
 	{
-		RelativePosition relpos(end_constant, i);
+		RelativePosition relpos(end(), i);
 		BOOST_CHECK_EQUAL(
 			sc.size() - 1 + i,
 			cx.sentence_context().get_abs_position(*relpos.apply(cx)));
@@ -120,20 +103,19 @@ BOOST_FIXTURE_TEST_CASE(rel_normal_pos, PosPredFix)
 {
 	for(int offset = -2; offset < 3; offset++)
 	{
-		for(int pos = -2; pos < 3; pos++)
+		for(int ppos = -2; ppos < 3; ppos++)
 		{
-			boost::shared_ptr<Constant<Position> > position(new Constant<Position>(Position(pos)));
-			RelativePosition relpos(position, offset);
+			RelativePosition relpos(pos(ppos), offset);
 			BOOST_CHECK_EQUAL(
-				offset + pos,
+				offset + ppos,
 				relpos.apply(cx)->get_value());
 			sc.advance();
 			BOOST_CHECK_EQUAL(
-				offset + pos,
+				offset + ppos,
 				relpos.apply(cx)->get_value());
 			sc.advance();
 			BOOST_CHECK_EQUAL(
-				offset + pos,
+				offset + ppos,
 				relpos.apply(cx)->get_value());
 			sc.goto_start();
 		}
@@ -144,21 +126,21 @@ BOOST_FIXTURE_TEST_CASE(rel_normal_pos, PosPredFix)
 
 BOOST_FIXTURE_TEST_CASE(relpos_to_string, PosPredFix)
 {
-	RelativePosition relpos(begin_constant, 4);
+	RelativePosition relpos(begin(), 4);
 	BOOST_CHECK_EQUAL("begin + 4", relpos.to_string(tagset));
-	RelativePosition relpos_min1(pos_minus_one_constant, -1);
+	RelativePosition relpos_min1(pos(-1), -1);
 	BOOST_CHECK_EQUAL("-1 - 1", relpos_min1.to_string(tagset));
-	RelativePosition relpos_zero(end_constant, 0);
+	RelativePosition relpos_zero(end(), 0);
 	BOOST_CHECK_EQUAL("end + 0", relpos_zero.to_string(tagset));
 }
 
 BOOST_FIXTURE_TEST_CASE(relpos_to_raw_string, PosPredFix)
 {
-	RelativePosition relpos(nowhere_constant, 42);
+	RelativePosition relpos(nowhere(), 42);
 	BOOST_CHECK_EQUAL("nowhere + 42", relpos.to_raw_string());
-	RelativePosition relpos_min1(pos_one_constant, -1);
+	RelativePosition relpos_min1(pos(1), -1);
 	BOOST_CHECK_EQUAL("1 - 1", relpos_min1.to_raw_string());
-	RelativePosition relpos_zero(end_constant, 0);
+	RelativePosition relpos_zero(end(), 0);
 	BOOST_CHECK_EQUAL("end + 0", relpos_zero.to_raw_string());
 }
 BOOST_AUTO_TEST_SUITE_END()
-- 
GitLab