<commit_before>
class List
	attr_reader :first
	attr_reader :rest
	
	def initialize(first=nil, rest=nil)
		@first = first
		@rest = rest
	end
end

class NamedAtom
	attr_reader :name
	
	def initialize(name)
		@name = name
	end
end

class Context
	def initialize(parent = nil)
		@parent = parent
		@values = Hash.new
	end
	
	def getValue(name)
		if @values.has_key?(name)
			return @values[name]
		end
		
		if @parent != nil
			return @parent.getValue(name)
		end
		
		return nil
	end
	
	def setValue(name, value)
		@values[name] = value
	end
end

require 'test/unit'

class ListTest < Test::Unit::TestCase
	def test_initialize
		list = List.new
		assert_not_nil(list)
	end
	
	def test_first_is_nil
		list = List.new
		assert_nil(list.first)
	end
	
	def test_rest_is_nil
		list = List.new
		assert_nil(list.rest)
	end
	
	def test_create_with_first
		list = List.new("foo")
		assert_equal("foo", list.first)
		assert_nil(list.rest)
	end
	
	def test_create_with_first_and_rest
		rest = List.new("bar")
		list = List.new("foo", rest)
		assert_equal("foo", list.first)
		assert_not_nil(list.rest)
		assert_equal("bar", list.rest.first)
		assert_nil(list.rest.rest)
	end
end

class NamedAtomTest < Test::Unit::TestCase
	def test_initialize
		atom = NamedAtom.new("a")
		assert_equal("a", atom.name)
	end
end

class ContextTest < Test::Unit::TestCase
	def test_initialize
		context = Context.new
		assert_not_nil(context)
	end
	
	def test_not_defined_is_nil
		context = Context.new
		assert_nil(context.getValue("foo"))
	end
	
	def test_set_and_get_value
		context = Context.new
		context.setValue("foo", "bar")
		assert_equal("bar", context.getValue("foo"))
	end
	
	def test_get_value_from_parent
		parent = Context.new
		parent.setValue("foo", "bar")
		context = Context.new(parent)
		assert_equal("bar", context.getValue("foo"))
	end<commit_msg>Atom evaluate in context, with tests<commit_after>
class List
	attr_reader :first
	attr_reader :rest
	
	def initialize(first=nil, rest=nil)
		@first = first
		@rest = rest
	end
end

class NamedAtom
	attr_reader :name
	
	def initialize(name)
		@name = name
	end
	
	def evaluate(context)
		return context.getValue(@name)
	end
end

class Context
	def initialize(parent = nil)
		@parent = parent
		@values = Hash.new
	end
	
	def getValue(name)
		if @values.has_key?(name)
			return @values[name]
		end
		
		if @parent != nil
			return @parent.getValue(name)
		end
		
		return nil
	end
	
	def setValue(name, value)
		@values[name] = value
	end
end

require 'test/unit'

class ListTest < Test::Unit::TestCase
	def test_initialize
		list = List.new
		assert_not_nil(list)
	end
	
	def test_first_is_nil
		list = List.new
		assert_nil(list.first)
	end
	
	def test_rest_is_nil
		list = List.new
		assert_nil(list.rest)
	end
	
	def test_create_with_first
		list = List.new("foo")
		assert_equal("foo", list.first)
		assert_nil(list.rest)
	end
	
	def test_create_with_first_and_rest
		rest = List.new("bar")
		list = List.new("foo", rest)
		assert_equal("foo", list.first)
		assert_not_nil(list.rest)
		assert_equal("bar", list.rest.first)
		assert_nil(list.rest.rest)
	end
end

class NamedAtomTest < Test::Unit::TestCase
	def test_initialize
		atom = NamedAtom.new("a")
		assert_equal("a", atom.name)
	end
	
	def test_evaluate_in_context
		atom = NamedAtom.new("foo")
		context = Context.new
		context.setValue("foo", "bar")
		assert_equal("bar", atom.evaluate(context))
	end 
end

class ContextTest < Test::Unit::TestCase
	def test_initialize
		context = Context.new
		assert_not_nil(context)
	end
	
	def test_not_defined_is_nil
		context = Context.new
		assert_nil(context.getValue("foo"))
	end
	
	def test_set_and_get_value
		context = Context.new
		context.setValue("foo", "bar")
		assert_equal("bar", context.getValue("foo"))
	end
	
	def test_get_value_from_parent
		parent = Context.new
		parent.setValue("foo", "bar")
		context = Context.new(parent)
		assert_equal("bar", context.getValue("foo"))
	end
{'fraction_non_alphanumeric': 0.1094742189484379, 'fraction_numerical': 0.0, 'mean_word_length': 4.181578947368421, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '1605541', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1422, 'n_words': 322}