test/unit/library_function_test.rb in hqmf2js-1.0.1 vs test/unit/library_function_test.rb in hqmf2js-1.1.0

- old
+ new

@@ -3,11 +3,11 @@ class LibraryFunctionTest < Test::Unit::TestCase def setup @context = get_js_context(HQMF2JS::Generator::JS.library_functions) - @context.eval("Specifics.initialize()") + @context.eval("hqmf.SpecificsManager.initialize()") end def test_library_function_parses @context.eval('hQuery == undefined').must_equal false @@ -83,19 +83,19 @@ def test_ts # TS - Timestamp 2010-01-01 ts = 'new TS("20110101")' ts2 = 'new TS("20100101")' ts3 = 'new TS("20120101")' - assert_equal 2011, @context.eval("#{ts}.asDate().getFullYear()") - assert_equal 0, @context.eval("#{ts}.asDate().getMonth()") - assert_equal 1, @context.eval("#{ts}.asDate().getDate()") - assert_equal 2012, @context.eval("#{ts}.add(new PQ(1, 'a')).asDate().getFullYear()") - assert_equal 2, @context.eval("#{ts}.add(new PQ(1, 'd')).asDate().getDate()") - assert_equal 8, @context.eval("#{ts}.add(new PQ(1, 'wk')).asDate().getDate()") - assert_equal 1, @context.eval("#{ts}.add(new PQ(1, 'h')).asDate().getHours()") - assert_equal 5, @context.eval("#{ts}.add(new PQ(5, 'min')).asDate().getMinutes()") - assert_equal 11, @context.eval("#{ts}.add(new PQ(-1, 'mo')).asDate().getMonth()") + assert_equal 2011, @context.eval("#{ts}.asDate().getUTCFullYear()") + assert_equal 0, @context.eval("#{ts}.asDate().getUTCMonth()") + assert_equal 1, @context.eval("#{ts}.asDate().getUTCDate()") + assert_equal 2012, @context.eval("#{ts}.add(new PQ(1, 'a')).asDate().getUTCFullYear()") + assert_equal 2, @context.eval("#{ts}.add(new PQ(1, 'd')).asDate().getUTCDate()") + assert_equal 8, @context.eval("#{ts}.add(new PQ(1, 'wk')).asDate().getUTCDate()") + assert_equal 1, @context.eval("#{ts}.add(new PQ(1, 'h')).asDate().getUTCHours()") + assert_equal 5, @context.eval("#{ts}.add(new PQ(5, 'min')).asDate().getUTCMinutes()") + assert_equal 11, @context.eval("#{ts}.add(new PQ(-1, 'mo')).asDate().getUTCMonth()") assert @context.eval("#{ts2}.before(#{ts})") assert @context.eval("#{ts3}.after(#{ts})") assert !@context.eval("#{ts}.before(#{ts2})") assert !@context.eval("#{ts}.after(#{ts3})") assert @context.eval("#{ts}.beforeOrConcurrent(#{ts})") @@ -258,11 +258,11 @@ def test_ivl_ts # IVL_TS - Time Range ivl1 = 'new IVL_TS(new TS("20120310"), new TS("20120320"))' ivl2 = 'new IVL_TS(new TS("20120312"), new TS("20120320"))' assert @context.eval("#{ivl2}.DURING(#{ivl1})") - assert_equal 2010, @context.eval('getIVL(new Date(2010,1,1)).low.asDate().getFullYear()') + assert_equal 2010, @context.eval('getIVL(new Date(Date.UTC(2010,1,1))).low.asDate().getUTCFullYear()') end def test_any_non_null # ANYNonNull ann = 'new ANYNonNull()' @@ -334,20 +334,24 @@ def test_temporal_operators # Events and bounds for temporal operators @context.eval('var events1 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120105"), new TS("20120105"));}}]') @context.eval('var events2 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120102"), new TS("20120105"));}}]') + @context.eval('var events3 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120105203030"), new TS("20120105203030"));}}]') @context.eval('var bound1 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120105"), new TS("20120105"));}}]') @context.eval('var bound2 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120107"), new TS("20120107"));}}]') @context.eval('var bound3 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120103"), new TS("20120107"));}}]') @context.eval('var bound4 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120106"), new TS("20120107"));}}]') @context.eval('var bound5 = {"asIVL_TS": function() {return new IVL_TS(new TS("20120106"), new TS("20120107"));}}') @context.eval('var nullStartBound = new IVL_TS(new TS("20120105"), new TS("20120105"));') @context.eval('nullStartBound.low.date = null;') @context.eval('var bound6 = {"asIVL_TS": function() {return nullStartBound;}}') + @context.eval('var bound7 = [{"asIVL_TS": function() {return new IVL_TS(new TS("20120105193030"), new TS("20120105193030"));}}]') @context.eval('var range1 = new IVL_PQ(null, new PQ(1, "d"))') @context.eval('var range2 = new IVL_PQ(new PQ(1, "d"), null)') + @context.eval('var range3 = new IVL_PQ(new PQ(0, "d"), null)') + @context.eval('var range4 = new IVL_PQ(null, new PQ(3, "d"))') # DURING assert_equal 1, @context.eval('DURING(events1, bound1)').count assert_equal 0, @context.eval('DURING(events1, bound2)').count assert_equal 1, @context.eval('DURING(events1, bound3)').count @@ -406,10 +410,11 @@ # SBS assert_equal 0, @context.eval('SBS(events1, bound1)').count assert_equal 0, @context.eval('SBS(events2, bound1, range1)').count assert_equal 1, @context.eval('SBS(events2, bound1)').count assert_equal 1, @context.eval('SBS(events2, bound1, range2)').count + assert_equal 0, @context.eval('SBS(events3, bound7, range3)').count # SAS assert_equal 0, @context.eval('SAS(events1, bound1)').count assert_equal 0, @context.eval('SAS(events2, bound1, range1)').count assert_equal 0, @context.eval('SAS(events2, bound1)').count @@ -468,9 +473,22 @@ assert_equal 0, @context.eval('SCWE(events1, bound2)').count # CONCURRENT assert_equal 1, @context.eval('CONCURRENT(events1, bound1)').count assert_equal 0, @context.eval('CONCURRENT(events1, bound2)').count + + #DATEDIFF + @context.eval('var diffEvent1 = {"asIVL_TS": function() {return new IVL_TS(new TS("20120105"), new TS("20120105"));}, "timeStamp": function() {return new Date(Date.UTC(2012, 1, 5, 0, 0));}}') + @context.eval('var diffEvent2 = {"asIVL_TS": function() {return new IVL_TS(new TS("20120107"), new TS("20120107"));}, "timeStamp": function() {return new Date(Date.UTC(2012, 1, 7, 0, 0));}}') + @context.eval('var diffEvent3 = {"asIVL_TS": function() {return new IVL_TS(new TS("20120111"), new TS("20120111"));}, "timeStamp": function() {return new Date(Date.UTC(2012, 1, 11, 0, 0));}}') + + assert_equal true, @context.eval('DATEDIFF([diffEvent1,diffEvent2],range4).isTrue()') + assert_equal true, @context.eval('DATEDIFF([diffEvent2,diffEvent1],range4).isTrue()') + assert_equal true, @context.eval('DATEDIFF([diffEvent1,diffEvent1],range4).isTrue()') + + # false test + + end def test_ordinal_operators # Ordinal operators ts20100101 = '{"timeStamp": function() {return new Date(2010,0,1);}}' \ No newline at end of file