| 1 | // Code generated by gen_tests.py and process_polyglot.py. |
| 2 | // Do not edit this file directly. |
| 3 | // The template for this file is located at: |
| 4 | // ../template.go.tpl |
| 5 | package reql_tests |
| 6 | |
| 7 | import ( |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
| 11 | "github.com/stretchr/testify/suite" |
| 12 | r "gopkg.in/rethinkdb/rethinkdb-go.v6" |
| 13 | "gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare" |
| 14 | ) |
| 15 | |
| 16 | // accessing portions |
| 17 | func TestTimesPortionsSuite(t *testing.T) { |
| 18 | suite.Run(t, new(TimesPortionsSuite)) |
| 19 | } |
| 20 | |
| 21 | type TimesPortionsSuite struct { |
| 22 | suite.Suite |
| 23 | |
| 24 | session *r.Session |
| 25 | } |
| 26 | |
| 27 | func (suite *TimesPortionsSuite) SetupTest() { |
| 28 | suite.T().Log("Setting up TimesPortionsSuite") |
| 29 | // Use imports to prevent errors |
| 30 | _ = time.Time{} |
| 31 | _ = compare.AnythingIsFine |
| 32 | |
| 33 | session, err := r.Connect(r.ConnectOpts{ |
| 34 | Address: url, |
| 35 | }) |
| 36 | suite.Require().NoError(err, "Error returned when connecting to server") |
| 37 | suite.session = session |
| 38 | |
| 39 | r.DBDrop("db_times_por").Exec(suite.session) |
| 40 | err = r.DBCreate("db_times_por").Exec(suite.session) |
| 41 | suite.Require().NoError(err) |
| 42 | err = r.DB("db_times_por").Wait().Exec(suite.session) |
| 43 | suite.Require().NoError(err) |
| 44 | |
| 45 | } |
| 46 | |
| 47 | func (suite *TimesPortionsSuite) TearDownSuite() { |
| 48 | suite.T().Log("Tearing down TimesPortionsSuite") |
| 49 | |
| 50 | if suite.session != nil { |
| 51 | r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session) |
| 52 | r.DBDrop("db_times_por").Exec(suite.session) |
| 53 | |
| 54 | suite.session.Close() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func (suite *TimesPortionsSuite) TestCases() { |
| 59 | suite.T().Log("Running TimesPortionsSuite: accessing portions") |
| 60 | |
| 61 | // times/portions.yaml line #3 |
| 62 | // rt1 = 1375147296.681 |
| 63 | suite.T().Log("Possibly executing: var rt1 float64 = 1375147296.681") |
| 64 | |
| 65 | rt1 := 1375147296.681 |
| 66 | _ = rt1 // Prevent any noused variable errors |
| 67 | |
| 68 | // times/portions.yaml line #4 |
| 69 | // rt2 = 1375147296.682 |
| 70 | suite.T().Log("Possibly executing: var rt2 float64 = 1375147296.682") |
| 71 | |
| 72 | rt2 := 1375147296.682 |
| 73 | _ = rt2 // Prevent any noused variable errors |
| 74 | |
| 75 | // times/portions.yaml line #5 |
| 76 | // rt3 = 1375147297.681 |
| 77 | suite.T().Log("Possibly executing: var rt3 float64 = 1375147297.681") |
| 78 | |
| 79 | rt3 := 1375147297.681 |
| 80 | _ = rt3 // Prevent any noused variable errors |
| 81 | |
| 82 | // times/portions.yaml line #6 |
| 83 | // rt4 = 2375147296.681 |
| 84 | suite.T().Log("Possibly executing: var rt4 float64 = 2375147296.681") |
| 85 | |
| 86 | rt4 := 2375147296.681 |
| 87 | _ = rt4 // Prevent any noused variable errors |
| 88 | |
| 89 | // times/portions.yaml line #7 |
| 90 | // rts = [rt1, rt2, rt3, rt4] |
| 91 | suite.T().Log("Possibly executing: var rts []interface{} = []interface{}{rt1, rt2, rt3, rt4}") |
| 92 | |
| 93 | rts := []interface{}{rt1, rt2, rt3, rt4} |
| 94 | _ = rts // Prevent any noused variable errors |
| 95 | |
| 96 | // times/portions.yaml line #9 |
| 97 | // t1 = r.epoch_time(rt1) |
| 98 | suite.T().Log("Possibly executing: var t1 r.Term = r.EpochTime(rt1)") |
| 99 | |
| 100 | t1 := r.EpochTime(rt1) |
| 101 | _ = t1 // Prevent any noused variable errors |
| 102 | |
| 103 | // times/portions.yaml line #10 |
| 104 | // t2 = r.epoch_time(rt2) |
| 105 | suite.T().Log("Possibly executing: var t2 r.Term = r.EpochTime(rt2)") |
| 106 | |
| 107 | t2 := r.EpochTime(rt2) |
| 108 | _ = t2 // Prevent any noused variable errors |
| 109 | |
| 110 | // times/portions.yaml line #11 |
| 111 | // t3 = r.epoch_time(rt3) |
| 112 | suite.T().Log("Possibly executing: var t3 r.Term = r.EpochTime(rt3)") |
| 113 | |
| 114 | t3 := r.EpochTime(rt3) |
| 115 | _ = t3 // Prevent any noused variable errors |
| 116 | |
| 117 | // times/portions.yaml line #12 |
| 118 | // t4 = r.epoch_time(rt4) |
| 119 | suite.T().Log("Possibly executing: var t4 r.Term = r.EpochTime(rt4)") |
| 120 | |
| 121 | t4 := r.EpochTime(rt4) |
| 122 | _ = t4 // Prevent any noused variable errors |
| 123 | |
| 124 | // times/portions.yaml line #13 |
| 125 | // ts = r.expr([t1, t2, t3, t4]) |
| 126 | suite.T().Log("Possibly executing: var ts r.Term = r.Expr([]interface{}{t1, t2, t3, t4})") |
| 127 | |
| 128 | ts := r.Expr([]interface{}{t1, t2, t3, t4}) |
| 129 | _ = ts // Prevent any noused variable errors |
| 130 | |
| 131 | { |
| 132 | // times/portions.yaml line #16 |
| 133 | /* ([1375142400, 1375142400, 1375142400, 2375136000]) */ |
| 134 | var expected_ []interface{} = []interface{}{1375142400, 1375142400, 1375142400, 2375136000} |
| 135 | /* ts.map(lambda x:x.date()).map(lambda x:x.to_epoch_time()) */ |
| 136 | |
| 137 | suite.T().Log("About to run line #16: ts.Map(func(x r.Term) interface{} { return x.Date()}).Map(func(x r.Term) interface{} { return x.ToEpochTime()})") |
| 138 | |
| 139 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { return x.Date() }).Map(func(x r.Term) interface{} { return x.ToEpochTime() }), suite.session, r.RunOpts{ |
| 140 | GeometryFormat: "raw", |
| 141 | GroupFormat: "map", |
| 142 | }) |
| 143 | suite.T().Log("Finished running line #16") |
| 144 | } |
| 145 | |
| 146 | { |
| 147 | // times/portions.yaml line #20 |
| 148 | /* ([0, 0, 0, 0]) */ |
| 149 | var expected_ []interface{} = []interface{}{0, 0, 0, 0} |
| 150 | /* ts.map(lambda x:x.date().time_of_day()) */ |
| 151 | |
| 152 | suite.T().Log("About to run line #20: ts.Map(func(x r.Term) interface{} { return x.Date().TimeOfDay()})") |
| 153 | |
| 154 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { return x.Date().TimeOfDay() }), suite.session, r.RunOpts{ |
| 155 | GeometryFormat: "raw", |
| 156 | GroupFormat: "map", |
| 157 | }) |
| 158 | suite.T().Log("Finished running line #20") |
| 159 | } |
| 160 | |
| 161 | { |
| 162 | // times/portions.yaml line #24 |
| 163 | /* ([4896.681, 4896.682, 4897.681, 11296.681]) */ |
| 164 | var expected_ []interface{} = []interface{}{4896.681, 4896.682, 4897.681, 11296.681} |
| 165 | /* ts.map(lambda x:x.time_of_day()) */ |
| 166 | |
| 167 | suite.T().Log("About to run line #24: ts.Map(func(x r.Term) interface{} { return x.TimeOfDay()})") |
| 168 | |
| 169 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { return x.TimeOfDay() }), suite.session, r.RunOpts{ |
| 170 | GeometryFormat: "raw", |
| 171 | GroupFormat: "map", |
| 172 | }) |
| 173 | suite.T().Log("Finished running line #24") |
| 174 | } |
| 175 | |
| 176 | { |
| 177 | // times/portions.yaml line #29 |
| 178 | /* ([[2013, 7, 30, 1, 21, 36.681], |
| 179 | [2013, 7, 30, 1, 21, 36.682], |
| 180 | [2013, 7, 30, 1, 21, 37.681], |
| 181 | [2045, 4, 7, 3, 8, 16.681]]) */ |
| 182 | var expected_ []interface{} = []interface{}{[]interface{}{2013, 7, 30, 1, 21, 36.681}, []interface{}{2013, 7, 30, 1, 21, 36.682}, []interface{}{2013, 7, 30, 1, 21, 37.681}, []interface{}{2045, 4, 7, 3, 8, 16.681}} |
| 183 | /* ts.map(lambda x:[x.year(), x.month(), x.day(), x.hours(), x.minutes(), x.seconds()]) */ |
| 184 | |
| 185 | suite.T().Log("About to run line #29: ts.Map(func(x r.Term) interface{} { return []interface{}{x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds()}})") |
| 186 | |
| 187 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { |
| 188 | return []interface{}{x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds()} |
| 189 | }), suite.session, r.RunOpts{ |
| 190 | GeometryFormat: "raw", |
| 191 | GroupFormat: "map", |
| 192 | }) |
| 193 | suite.T().Log("Finished running line #29") |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | // times/portions.yaml line #36 |
| 198 | /* rts */ |
| 199 | var expected_ []interface{} = rts |
| 200 | /* ts.map(lambda x:r.time(x.year(), x.month(), x.day(), x.hours(), x.minutes(), x.seconds(), x.timezone())).map(lambda x:x.to_epoch_time()) */ |
| 201 | |
| 202 | suite.T().Log("About to run line #36: ts.Map(func(x r.Term) interface{} { return r.Time(x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds(), x.Timezone())}).Map(func(x r.Term) interface{} { return x.ToEpochTime()})") |
| 203 | |
| 204 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { |
| 205 | return r.Time(x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds(), x.Timezone()) |
| 206 | }).Map(func(x r.Term) interface{} { return x.ToEpochTime() }), suite.session, r.RunOpts{ |
| 207 | GeometryFormat: "raw", |
| 208 | GroupFormat: "map", |
| 209 | }) |
| 210 | suite.T().Log("Finished running line #36") |
| 211 | } |
| 212 | |
| 213 | { |
| 214 | // times/portions.yaml line #40 |
| 215 | /* 0 */ |
| 216 | var expected_ int = 0 |
| 217 | /* ts.map(lambda x:r.time(x.year(), x.month(), x.day(), x.hours(), x.minutes(), x.seconds(), x.timezone())).union(ts).map(lambda x:x.to_iso8601()).distinct().count().sub(ts.count()) */ |
| 218 | |
| 219 | suite.T().Log("About to run line #40: ts.Map(func(x r.Term) interface{} { return r.Time(x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds(), x.Timezone())}).Union(ts).Map(func(x r.Term) interface{} { return x.ToISO8601()}).Distinct().Count().Sub(ts.Count())") |
| 220 | |
| 221 | runAndAssert(suite.Suite, expected_, ts.Map(func(x r.Term) interface{} { |
| 222 | return r.Time(x.Year(), x.Month(), x.Day(), x.Hours(), x.Minutes(), x.Seconds(), x.Timezone()) |
| 223 | }).Union(ts).Map(func(x r.Term) interface{} { return x.ToISO8601() }).Distinct().Count().Sub(ts.Count()), suite.session, r.RunOpts{ |
| 224 | GeometryFormat: "raw", |
| 225 | GroupFormat: "map", |
| 226 | }) |
| 227 | suite.T().Log("Finished running line #40") |
| 228 | } |
| 229 | |
| 230 | { |
| 231 | // times/portions.yaml line #44 |
| 232 | /* [[2, 211], [2, 211], [2, 211], [5, 97]] */ |
| 233 | var expected_ []interface{} = []interface{}{[]interface{}{2, 211}, []interface{}{2, 211}, []interface{}{2, 211}, []interface{}{5, 97}} |
| 234 | /* ts.map([r.row.day_of_week(), r.row.day_of_year()]) */ |
| 235 | |
| 236 | suite.T().Log("About to run line #44: ts.Map([]interface{}{r.Row.DayOfWeek(), r.Row.DayOfYear()})") |
| 237 | |
| 238 | runAndAssert(suite.Suite, expected_, ts.Map([]interface{}{r.Row.DayOfWeek(), r.Row.DayOfYear()}), suite.session, r.RunOpts{ |
| 239 | GeometryFormat: "raw", |
| 240 | GroupFormat: "map", |
| 241 | }) |
| 242 | suite.T().Log("Finished running line #44") |
| 243 | } |
| 244 | } |