mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/maintenance/autotest/obj_test/calc_test/fractions_sums_test.py
00001 # -*- coding: utf-8 -*-
00002 
00003 # Mathmaker creates automatically maths exercises sheets
00004 # with their answers
00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net>
00006 
00007 # This file is part of Mathmaker.
00008 
00009 # Mathmaker is free software; you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation; either version 3 of the License, or
00012 # any later version.
00013 
00014 # Mathmaker is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 
00019 # You should have received a copy of the GNU General Public License
00020 # along with Mathmaker; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 import os
00024 import sys
00025 
00026 from core import *
00027 from core.base_calculus import *
00028 
00029 from maintenance.autotest import common
00030 
00031 check = common.check
00032 
00033 
00034 def action():
00035     if common.verbose:
00036         os.write(common.output, bytes("--- FRACTIONS SUMS\n", 'utf-8'))
00037 
00038     fraction_2_3_plus_fraction_3_4 = Sum([Fraction(('+', 2, 3)),
00039                                           Fraction(('+', 3, 4))])
00040 
00041     fraction_1_4_plus_fraction_1_8 = Sum([Fraction(('+', 1, 4)),
00042                                           Fraction(('+', 1, 8))])
00043 
00044     fraction_1_9_plus_fraction_1_minus12 = Sum([Fraction(('+', 1, 9)),
00045                                                 Fraction(('+', 1, -12))])
00046 
00047     fraction_minus7_10_plus_fraction_minus11_minus15 = \
00048                                      Sum([Fraction(('+', -7, 10)),
00049                                           Fraction(('-', 11, -15))])
00050 
00051     sum_of_fraction_3_4_and_number_minus2 = Sum([Fraction(('+', 3, 4)),
00052                                                  Item(-5)])
00053 
00054     sum_of_fraction_25_10_and_1_10 = Sum([Fraction(('+', 25, 10)),
00055                                           Fraction(('+', 1, 10))])
00056 
00057     sum_of_fraction_minus18_5_minus_2_5 = Sum([Fraction(('-', 18, 5)),
00058                                                Fraction(('-', 2, 5))])
00059 
00060     #4 + 25/10 - 7 + 1/10
00061     long_sum = Sum([Item(4),
00062                     Fraction((25, 10)),
00063                     Item(-7),
00064                     Fraction((1, 10))])
00065 
00066 
00067     # 01
00068     check(fraction_2_3_plus_fraction_3_4,
00069          ["\\frac{2}{3}+\\frac{3}{4}"])
00070 
00071     # 02
00072     step_1 = fraction_2_3_plus_fraction_3_4.calculate_next_step()
00073     check(step_1,
00074          ["\\frac{2\\times 4}{3\\times 4}+\\frac{3\\times 3}{4\\times 3}"])
00075 
00076     step_2 = step_1.calculate_next_step()
00077     check(step_2,
00078          ["\\frac{8}{12}+\\frac{9}{12}"])
00079 
00080     step_3 = step_2.calculate_next_step()
00081     check(step_3,
00082          ["\\frac{8+9}{12}"])
00083 
00084     # 05
00085     step_4 = step_3.calculate_next_step()
00086     check(step_4,
00087          ["\\frac{17}{12}"])
00088 
00089     step_5 = step_4.calculate_next_step()
00090     check(step_5,
00091          ["None"])
00092 
00093     check(fraction_1_4_plus_fraction_1_8,
00094          ["\\frac{1}{4}+\\frac{1}{8}"])
00095 
00096     step_1 = fraction_1_4_plus_fraction_1_8.calculate_next_step()
00097     check(step_1,
00098          ["\\frac{1\\times 2}{4\\times 2}+\\frac{1}{8}"])
00099 
00100     step_2 = step_1.calculate_next_step()
00101     check(step_2,
00102          ["\\frac{2}{8}+\\frac{1}{8}"])
00103 
00104     # 10
00105     step_3 = step_2.calculate_next_step()
00106     check(step_3,
00107          ["\\frac{2+1}{8}"])
00108 
00109     step_4 = step_3.calculate_next_step()
00110     check(step_4,
00111          ["\\frac{3}{8}"])
00112 
00113     step_5 = step_4.calculate_next_step()
00114     check(step_5,
00115          ["None"])
00116 
00117     check(fraction_1_9_plus_fraction_1_minus12,
00118          ["\\frac{1}{9}+\\frac{1}{-12}"])
00119 
00120     step_1 = fraction_1_9_plus_fraction_1_minus12.calculate_next_step()
00121     check(step_1,
00122          ["\\frac{1}{9}-\\frac{1}{12}"])
00123 
00124     # 15
00125     step_2 = step_1.calculate_next_step()
00126     check(step_2,
00127          ["\\frac{1\\times 4}{9\\times 4}-\\frac{1\\times 3}{12\\times 3}"])
00128 
00129     step_3 = step_2.calculate_next_step()
00130     check(step_3,
00131          ["\\frac{4}{36}-\\frac{3}{36}"])
00132 
00133     step_4 = step_3.calculate_next_step()
00134     check(step_4,
00135          ["\\frac{4-3}{36}"])
00136 
00137     step_5 = step_4.calculate_next_step()
00138     check(step_5,
00139          ["\\frac{1}{36}"])
00140 
00141     step_6 = step_5.calculate_next_step()
00142     check(step_6,
00143          ["None"])
00144 
00145 
00146     # 20
00147     check(fraction_minus7_10_plus_fraction_minus11_minus15,
00148          ["\\frac{-7}{10}-\\frac{11}{-15}"])
00149 
00150     step_1 = fraction_minus7_10_plus_fraction_minus11_minus15.\
00151              calculate_next_step()
00152     check(step_1,
00153          ["-\\frac{7}{10}+\\frac{11}{15}"])
00154 
00155     step_2 = step_1.calculate_next_step()
00156     check(step_2,
00157         ["-\\frac{7\\times 3}{10\\times 3}+\\frac{11\\times 2}{15\\times 2}"])
00158 
00159     step_3 = step_2.calculate_next_step()
00160     check(step_3,
00161          ["-\\frac{21}{30}+\\frac{22}{30}"])
00162 
00163     # 24
00164     step_4 = step_3.calculate_next_step()
00165     check(step_4,
00166          ["\\frac{-21+22}{30}"])
00167 
00168     # 25
00169     step_5 = step_4.calculate_next_step()
00170     check(step_5,
00171          ["\\frac{1}{30}"])
00172 
00173     step_6 = step_5.calculate_next_step()
00174     check(step_6,
00175          ["None"])
00176 
00177 
00178     check(sum_of_fraction_3_4_and_number_minus2,
00179          ["\\frac{3}{4}-5"])
00180 
00181     step_1 = sum_of_fraction_3_4_and_number_minus2.calculate_next_step()
00182     check(step_1,
00183          ["\\frac{3}{4}-\\frac{5}{1}"])
00184 
00185     # 29
00186     step_2 = step_1.calculate_next_step()
00187     check(step_2,
00188          ["\\frac{3}{4}-\\frac{5\\times 4}{1\\times 4}"])
00189 
00190     step_3 = step_2.calculate_next_step()
00191     check(step_3,
00192          ["\\frac{3}{4}-\\frac{20}{4}"])
00193 
00194     step_4 = step_3.calculate_next_step()
00195     check(step_4,
00196          ["\\frac{3-20}{4}"])
00197 
00198     step_5 = step_4.calculate_next_step()
00199     check(step_5,
00200          ["-\\frac{17}{4}"])
00201 
00202     step_6 = step_5.calculate_next_step()
00203     check(step_6,
00204          ["None"])
00205 
00206 
00207 
00208     # 34
00209     check(sum_of_fraction_25_10_and_1_10,
00210          ["\\frac{25}{10}+\\frac{1}{10}"])
00211 
00212     step_1 = sum_of_fraction_25_10_and_1_10.calculate_next_step()
00213     check(step_1,
00214          ["\\frac{25+1}{10}"])
00215 
00216     step_2 = step_1.calculate_next_step()
00217     check(step_2,
00218          ["\\frac{26}{10}"])
00219 
00220     step_3 = step_2.calculate_next_step()
00221     check(step_3,
00222          ["\\frac{\\bcancel{2}\\times 13}{\\bcancel{2}\\times 5}"])
00223 
00224     step_4 = step_3.calculate_next_step()
00225     check(step_4,
00226          ["\\frac{13}{5}"])
00227 
00228     # 39
00229     step_5 = step_4.calculate_next_step()
00230     check(step_5,
00231          ["None"])
00232 
00233 
00234 
00235 
00236 
00237 
00238     check(sum_of_fraction_minus18_5_minus_2_5,
00239          ["-\\frac{18}{5}-\\frac{2}{5}"])
00240 
00241     # 41
00242     step_1 = sum_of_fraction_minus18_5_minus_2_5.calculate_next_step()
00243     check(step_1,
00244          ["\\frac{-18-2}{5}"])
00245 
00246     step_2 = step_1.calculate_next_step()
00247     check(step_2,
00248          ["-\\frac{20}{5}"])
00249 
00250     step_3 = step_2.calculate_next_step()
00251     check(step_3,
00252          ["-\\frac{\\bcancel{5}\\times 4}{\\bcancel{5}}"])
00253 
00254     step_4 = step_3.calculate_next_step()
00255     check(step_4,
00256          ["-4"])
00257 
00258     step_5 = step_4.calculate_next_step()
00259     check(step_5,
00260          ["None"])
00261 
00262 
00263     # 46
00264     check(long_sum,
00265          ["4+\\frac{25}{10}-7+\\frac{1}{10}"])
00266 
00267     step_1 = long_sum.calculate_next_step()
00268     check(step_1,
00269          ["4-7+\\frac{25+1}{10}"])
00270 
00271     step_2 = step_1.calculate_next_step()
00272     check(step_2,
00273          ["-3+\\frac{26}{10}"])
00274 
00275     step_3 = step_2.calculate_next_step()
00276     check(step_3,
00277          ["-3+\\frac{\\bcancel{2}\\times 13}{\\bcancel{2}\\times 5}"])
00278 
00279     step_4 = step_3.calculate_next_step()
00280     check(step_4,
00281          ["-3+\\frac{13}{5}"])
00282 
00283     step_5 = step_4.calculate_next_step()
00284     check(step_5,
00285          ["-\\frac{3}{1}+\\frac{13}{5}"])
00286 
00287     # 52
00288     step_6 = step_5.calculate_next_step()
00289     check(step_6,
00290          ["-\\frac{3\\times 5}{1\\times 5}+\\frac{13}{5}"])
00291 
00292     step_7 = step_6.calculate_next_step()
00293     check(step_7,
00294          ["-\\frac{15}{5}+\\frac{13}{5}"])
00295 
00296 
00297