Sha256: 3a7c6d3f18efcc598e9b98f94305160b0e74c4c295fa0622ea6aaaa2db85837e

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require 'helper'

class TestTextFileTools < Test::Unit::TestCase
	def test_1d
		assert_raise(ArgumentError){TextFileTools.get_1d_array('test/test_dat.dat', true, 2.2)} 
		assert_raise(ArgumentError){TextFileTools.get_1d_array('test/test_dat.dat',true, /ii\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)} 
		array = TextFileTools.get_1d_array('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
		#puts array
		assert_equal(array.size, 18)
		assert_equal(array[9].to_f, 0.9753E+09)
		array = TextFileTools.get_1d_array_float('test/test_dat.dat', true, /i\+ temp/, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
		assert_equal(array[9], 0.9753E+09)
	end
	def test_2d
		array = TextFileTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
		assert_equal(array.size, 2)
		array = TextFileTools.get_2d_array('test/test_dat.dat', true, /i\+ temp/, 1, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
		assert_equal(array.size, 18)
		array = TextFileTools.get_2d_array_float('test/test_dat.dat', true, /i\+ temp/, 0, /\S+/, /(?:\#\s+)?\d:.*?(?=\d:)/)
		assert_equal(array[0].size, 9)
		assert_equal(array[1][0], 0.9753E+09)

		#assert_equal(array[9].to_f, 0.9753E+09)

	end
	def test_get_variable
		variable = TextFileTools.get_variable_value('test/test_dat_2.dat', 'Q', ':')
		assert_equal(variable.to_f, 11.989644168449118)
		variable = TextFileTools.get_variable_value('test/test_dat_2.dat', 'Fusion power', ':')
		assert_equal(variable.to_f, 484.34196189744871)
	end
	def test_texdatafile_class
		file = TextFileTools::TextDataFile.new('test/test_dat_2.dat')
		assert_equal(file.get_variable_value('Alpha power', ':').to_f, 116.90499891894469 )
		file = TextFileTools::TextDataFile.new('test/test_dat.dat', true, /\S+/,  /(?:\#\s+)?\d:.*?(?=\d:)/)
		array = file.get_2d_array(/i\+ temp/, /1.*time/)
		assert_equal(array.size, 2)
	end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
text-data-tools-1.0.4 test/test_text-data-tools.rb
text-data-tools-1.0.3 test/test_text-data-tools.rb
text-data-tools-1.0.2 test/test_text-data-tools.rb
text-data-tools-1.0.1 test/test_text-data-tools.rb
text-data-tools-1.0.0 test/test_text-data-tools.rb