mathmaker
0.6(alpha)
|
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 from lib.maths_lib import * 00029 00030 from maintenance.autotest import common 00031 00032 check = common.check 00033 00034 00035 def action(): 00036 if common.verbose: 00037 os.write(common.output, bytes("--- FRACTION SIMPLIFICATION\n", 'utf-8')) 00038 00039 fraction_92_76 = Fraction(('+', 92, 76)) 00040 fraction_92_76_bis = Fraction(('+', 92, 76)) 00041 fraction_10times6_over_7times2 = Fraction(('+', 00042 Product([Item(10), Item(6)]), 00043 Product([Item(7), Item(2)]) 00044 )) 00045 00046 fraction_7times6_over_3times3 = Fraction(('+', 00047 Product([Item(7), Item(6)]), 00048 Product([Item(3), Item(3)]) 00049 )) 00050 00051 fraction_3times7_over_10times4 = Fraction(('+', 00052 Product([Item(3), Item(7)]), 00053 Product([Item(10), Item(4)]) 00054 )) 00055 00056 fraction_8times3_over_5times6 = Fraction(('+', 00057 Product([Item(8), Item(3)]), 00058 Product([Item(5), Item(6)]) 00059 )) 00060 00061 fraction_10times5_over_5times9 = Fraction(('+', 00062 Product([Item(10), Item(5)]), 00063 Product([Item(5), Item(9)]) 00064 )) 00065 00066 #fraction_minus3timesminus1_over_minus2times9 = Fraction(( \ 00067 # '+', 00068 # Product([Item(-3), 00069 # Item(-1)]), 00070 # Product([Item(-2), 00071 # Item(9)]) 00072 # )) 00073 00074 check(str(ten_power_gcd(3,4)), 00075 ["1"]) 00076 00077 check(str(ten_power_gcd(10,4)), 00078 ["1"]) 00079 00080 check(str(ten_power_gcd(10,10)), 00081 ["10"]) 00082 00083 check(str(ten_power_gcd(200,50)), 00084 ["10"]) 00085 00086 check(str(ten_power_gcd(21000,400)), 00087 ["100"]) 00088 00089 check(fraction_92_76, 00090 ["\\frac{92}{76}"]) 00091 00092 fraction_92_76 = fraction_92_76.calculate_next_step() 00093 check(fraction_92_76, 00094 ["\\frac{\\bcancel{2}\\times 46}{\\bcancel{2}\\times 38}"]) 00095 00096 fraction_92_76 = fraction_92_76.calculate_next_step() 00097 check(fraction_92_76, 00098 ["\\frac{\\bcancel{2}\\times 23}{\\bcancel{2}\\times 19}"]) 00099 00100 check(fraction_92_76_bis.simplified(), 00101 ["\\frac{46}{38}"]) 00102 00103 check(fraction_92_76_bis.simplification_line().simplified(), 00104 ["\\frac{46}{38}"]) 00105 00106 #check(fraction_10times6_over_7times2, 00107 # ["essai"]) 00108 00109 check(fraction_10times6_over_7times2.is_reducible(), 00110 ["True"]) 00111 00112 check(fraction_10times6_over_7times2.calculate_next_step(), 00113 ["\\frac{\\bcancel{2}\\times 5\\times 6}{7\\times \\bcancel{2}}"]) 00114 00115 check(fraction_7times6_over_3times3.simplification_line(), 00116 ["\\frac{7\\times \\bcancel{3}\\times 2}{\\bcancel{3}\\times 3}"]) 00117 00118 check(fraction_3times7_over_10times4.calculate_next_step(), 00119 ["\\frac{21}{40}"]) 00120 00121 check(fraction_8times3_over_5times6.simplification_line(), 00122 ["\\frac{\\bcancel{2}\\times 4\\times \\bcancel{3}}{5\\times" \ 00123 + " \\bcancel{2}\\times \\bcancel{3}}"]) 00124 00125 check(fraction_10times5_over_5times9.simplification_line(), 00126 ["\\frac{10\\times \\bcancel{5}}{\\bcancel{5}\\times 9}"]) 00127 00128 00129 f1 = Fraction(('+', 3, 7)) 00130 00131 check(f1.completely_reduced(), 00132 ["\\frac{3}{7}"]) 00133 00134 check(str(f1.is_a_decimal_number()), 00135 ["False"]) 00136 00137 f2 = Fraction(('+', 9, 700)) 00138 00139 check(str(f2.is_a_decimal_number()), 00140 ["False"]) 00141 00142 f3 = Fraction(('+', 9, 2500)) 00143 00144 check(str(f3.is_a_decimal_number()), 00145 ["True"]) 00146 00147 f4 = Fraction(('+', 7, 700)) 00148 00149 check(str(f4.is_a_decimal_number()), 00150 ["True"]) 00151 00152