File: reql_math_logic_math_test.go

package info (click to toggle)
golang-gopkg-rethinkdb-rethinkdb-go.v6 6.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,736 kB
  • sloc: python: 1,382; makefile: 16; sh: 9
file content (75 lines) | stat: -rw-r--r-- 1,956 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Code generated by gen_tests.py and process_polyglot.py.
// Do not edit this file directly.
// The template for this file is located at:
// ../template.go.tpl
package reql_tests

import (
	"testing"
	"time"

	"github.com/stretchr/testify/suite"
	r "gopkg.in/rethinkdb/rethinkdb-go.v6"
	"gopkg.in/rethinkdb/rethinkdb-go.v6/internal/compare"
)

// Tests of nested arithmetic expressions
func TestMathLogicMathSuite(t *testing.T) {
	suite.Run(t, new(MathLogicMathSuite))
}

type MathLogicMathSuite struct {
	suite.Suite

	session *r.Session
}

func (suite *MathLogicMathSuite) SetupTest() {
	suite.T().Log("Setting up MathLogicMathSuite")
	// Use imports to prevent errors
	_ = time.Time{}
	_ = compare.AnythingIsFine

	session, err := r.Connect(r.ConnectOpts{
		Address: url,
	})
	suite.Require().NoError(err, "Error returned when connecting to server")
	suite.session = session

	r.DBDrop("db_logic_math").Exec(suite.session)
	err = r.DBCreate("db_logic_math").Exec(suite.session)
	suite.Require().NoError(err)
	err = r.DB("db_logic_math").Wait().Exec(suite.session)
	suite.Require().NoError(err)

}

func (suite *MathLogicMathSuite) TearDownSuite() {
	suite.T().Log("Tearing down MathLogicMathSuite")

	if suite.session != nil {
		r.DB("rethinkdb").Table("_debug_scratch").Delete().Exec(suite.session)
		r.DBDrop("db_logic_math").Exec(suite.session)

		suite.session.Close()
	}
}

func (suite *MathLogicMathSuite) TestCases() {
	suite.T().Log("Running MathLogicMathSuite: Tests of nested arithmetic expressions")

	{
		// math_logic/math.yaml line #4
		/* 1 */
		var expected_ int = 1
		/* (((4 + 2 * (r.expr(26) % 18)) / 5) - 3) */

		suite.T().Log("About to run line #4: r.Add(4, r.Mul(2, r.Expr(26).Mod(18))).Div(5).Sub(3)")

		runAndAssert(suite.Suite, expected_, r.Add(4, r.Mul(2, r.Expr(26).Mod(18))).Div(5).Sub(3), suite.session, r.RunOpts{
			GeometryFormat: "raw",
			GroupFormat:    "map",
		})
		suite.T().Log("Finished running line #4")
	}
}