OSDN Git Service

add arithmetic solver
[mint/mint-lib.git] / spec / spec_helper.rb
1 # -*- coding: utf-8 -*-
2
3 $:.unshift File.dirname(__FILE__) + '/../lib'
4 require 'mint'
5
6 module ProblemExamples
7
8   def self.get(*types)
9     types.inject([]) {|memo, type|
10       memo += __send__(type)
11     }
12   end
13
14   private
15   def self.existing
16     [
17       ['7 / 12 + 17 / 12', '7 / 12 + 17 / 12'],
18       ['3 / 4 + 1 / 7', '3 / 4 + 1 / 7'],
19       ['2 / 9 - 3 / 5', '2 / 9 - 3 / 5'],
20       ['2', '2'],
21       ['4/11', '4 / 11'],
22       ['25/28', '25 / 28'],
23       ['-7/12', '-7 / 12'],
24       ['-17/45','-17 / 45' ],
25       ['(2a + 1)(3a - 2)', '(2 * a + 1) * (3 * a - 2)'],
26       ['(x + 2)^2', '(x + 2)^2'],
27       ['(3P - 2Q)^3', '(3 * P - 2 * Q)^3'],
28       ['1 / (x + 1)(x + 2)', '1 / (x + 1) * (x + 2)'],
29       ['2x^3 + x - 1', '2 * x^3 + x - 1'],
30       ['(X^2 - Y^2)', '(X^2 - Y^2)'],
31       ['root(2)root(8)', 'sqrt(2) * sqrt(8)'],
32       ['sqrt(2)sqrt(8)', 'sqrt(2) * sqrt(8)'],
33       ['(1 + root(3))(2 - root(3))', '(1 + sqrt(3)) * (2 - sqrt(3))'],
34       ['(1 + sqrt(3))(2 - sqrt(3))', '(1 + sqrt(3)) * (2 - sqrt(3))'],
35       ['1 / root(2)', '1 / sqrt(2)'],
36       ['1 / sqrt(2)', '1 / sqrt(2)'],
37       ['2 / (root(3) - 1)', '2 / (sqrt(3) - 1)'],
38       ['2 / (sqrt(3) - 1)', '2 / (sqrt(3) - 1)'],
39     ]
40   end
41
42   def self.original
43     [
44       ['1 + 1', '1 + 1'],
45       ['2 - 2', '2 - 2'],
46       ['3 * 3', '3 * 3'],
47       ['4 / 4', '4 / 4'],
48       ['5 div 5', '5 div 5'],
49       ['-233/23', '-233 / 23'],
50                         ['(x^2 + 4)(y^3 - 2)', '(x^2 + 4) * (y^3 - 2)'],
51                         ['(x^3 + 2)(x^2- 3)', '(x^3 + 2) * (x^2 - 3)'],
52       ['2(x^2 + xy + y^2)', '2 * (x^2 + x * y + y^2)'],
53       ['sqrt(2(x^(2 + 3) + xyz^5 + y^2))', 'sqrt(2 * (x^(2 + 3) + x * y * z^5 + y^2))'],
54       ['sqrt(2(x^(2 + 3) + root(xyz^5) + y^2))', 'sqrt(2 * (x^(2 + 3) + sqrt(x * y * z^5) + y^2))'],
55       ['5xc*1div5 + 1 (34 - 1 /8 + 1)', '5 * x * c * 1 div 5 + 1 * (34 - 1 / 8 + 1)'],
56       ['2PI', '2 * %pi'],
57       ['5.8*5.8*PI', '5.8 * 5.8 * %pi'],
58       ['3e * 5x^2', '3 * %e * 5 * x^2'],
59       ['3E * 5x^2', '3 * %e * 5 * x^2'],
60       ['3 + 2i', '3 + 2 * %i'],
61       ['(-24x + 37)(71x - 33)', '(-24 * x + 37) * (71 * x - 33)'],
62       ['x^((3y^2+5y)(y^2+2-x))', 'x^((3 * y^2 + 5 * y) * (y^2 + 2 - x))'],
63       ['-x^(-(-3y^2+-5y)(y^-2+2-x))', '-x^(-(-3 * y^2 + -5 * y) * (y^-2 + 2 - x))'],
64       ['(x^3 + 1)(x^2 + 2)(x + 1)', '(x^3 + 1) * (x^2 + 2) * (x + 1)'],
65       ['(x^3 + 1)(x^2 + 2)(x + 1)(y^2 - 11)', '(x^3 + 1) * (x^2 + 2) * (x + 1) * (y^2 - 11)'],
66       ['(x^3 + 1)(x^2 + 2)(x + 1)(y^2 - 11)(y^3 - 4)', '(x^3 + 1) * (x^2 + 2) * (x + 1) * (y^2 - 11) * (y^3 - 4)'],
67       # TODO: need more pattern
68
69       # divide and fraction
70       ['5 div 4', '5 div 4'],
71       ['5.0 div 4', '5.0 div 4'],
72       ['5/4', '5 / 4'],
73       ['5.0/4', '5.0 / 4'],
74     ]
75   end
76 end
77