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 import locale 00026 00027 from lib.common import default 00028 00029 from core import * 00030 from core.base_calculus import * 00031 00032 from maintenance.autotest import common 00033 00034 try: 00035 locale.setlocale(locale.LC_ALL, default.LANGUAGE + '.' + default.ENCODING) 00036 except: 00037 locale.setlocale(locale.LC_ALL, '') 00038 00039 check = common.check 00040 00041 00042 def action(): 00043 if common.verbose: 00044 os.write(common.output, bytes("--- VALUES\n", 'utf-8')) 00045 00046 integer_value = Value(4) 00047 00048 one_digit_value = Value(4.2) 00049 00050 two_digits_value = Value(4.25) 00051 00052 three_digits_value = Value(4.257) 00053 00054 four_digits_value = Value(4.2571) 00055 00056 perfect_square = Value(16) 00057 00058 perfect_decimal_square = Value(1.96) 00059 00060 # 01 00061 check(integer_value.digits_number(), 00062 ["0"]) 00063 00064 check(one_digit_value.digits_number(), 00065 ["1"]) 00066 00067 check(two_digits_value.digits_number(), 00068 ["2"]) 00069 00070 check(three_digits_value.digits_number(), 00071 ["3"]) 00072 00073 check(four_digits_value.digits_number(), 00074 ["4"]) 00075 00076 check(integer_value.round(0), 00077 ["4"]) 00078 00079 check(one_digit_value.round(0), 00080 ["4"]) 00081 00082 check(two_digits_value.round(0), 00083 ["4"]) 00084 00085 check(three_digits_value.round(0), 00086 ["4"]) 00087 00088 # 10 00089 check(four_digits_value.round(0), 00090 ["4"]) 00091 00092 check(integer_value.round(1), 00093 ["4"]) 00094 00095 check(one_digit_value.round(1), 00096 [locale.str(4.2)]) 00097 00098 check(two_digits_value.round(1), 00099 [locale.str(4.3)]) 00100 00101 check(three_digits_value.round(1), 00102 [locale.str(4.3)]) 00103 00104 check(four_digits_value.round(1), 00105 [locale.str(4.3)]) 00106 00107 check(integer_value.round(2), 00108 ["4"]) 00109 00110 check(one_digit_value.round(2), 00111 [locale.str(4.2)]) 00112 00113 check(two_digits_value.round(2), 00114 [locale.str(4.25)]) 00115 00116 check(three_digits_value.round(2), 00117 [locale.str(4.26)]) 00118 00119 check(four_digits_value.round(2), 00120 [locale.str(4.26)]) 00121 00122 check(integer_value.round(3), 00123 ["4"]) 00124 00125 check(one_digit_value.round(3), 00126 [locale.str(4.2)]) 00127 00128 check(two_digits_value.round(3), 00129 [locale.str(4.25)]) 00130 00131 check(three_digits_value.round(3), 00132 [locale.str(4.257)]) 00133 00134 check(four_digits_value.round(3), 00135 [locale.str(4.257)]) 00136 00137 check(integer_value.round(4), 00138 ["4"]) 00139 00140 check(one_digit_value.round(4), 00141 [locale.str(4.2)]) 00142 00143 check(two_digits_value.round(4), 00144 [locale.str(4.25)]) 00145 00146 check(three_digits_value.round(4), 00147 [locale.str(4.257)]) 00148 00149 check(four_digits_value.round(4), 00150 [locale.str(4.2571)]) 00151 00152 check(integer_value.needs_to_get_rounded(0), 00153 ["False"]) 00154 00155 check(integer_value.needs_to_get_rounded(1), 00156 ["False"]) 00157 00158 check(one_digit_value.needs_to_get_rounded(0), 00159 ["True"]) 00160 00161 check(one_digit_value.needs_to_get_rounded(1), 00162 ["False"]) 00163 00164 check(one_digit_value.needs_to_get_rounded(2), 00165 ["False"]) 00166 00167 check(two_digits_value.needs_to_get_rounded(0), 00168 ["True"]) 00169 00170 check(two_digits_value.needs_to_get_rounded(1), 00171 ["True"]) 00172 00173 check(two_digits_value.needs_to_get_rounded(2), 00174 ["False"]) 00175 00176 check(three_digits_value.needs_to_get_rounded(0), 00177 ["True"]) 00178 00179 check(three_digits_value.needs_to_get_rounded(1), 00180 ["True"]) 00181 00182 check(three_digits_value.needs_to_get_rounded(2), 00183 ["True"]) 00184 00185 check(three_digits_value.needs_to_get_rounded(3), 00186 ["False"]) 00187 00188 check(four_digits_value.needs_to_get_rounded(0), 00189 ["True"]) 00190 00191 check(four_digits_value.needs_to_get_rounded(1), 00192 ["True"]) 00193 00194 check(four_digits_value.needs_to_get_rounded(2), 00195 ["True"]) 00196 00197 check(four_digits_value.needs_to_get_rounded(3), 00198 ["True"]) 00199 00200 check(four_digits_value.needs_to_get_rounded(4), 00201 ["False"]) 00202 00203 check(perfect_square.is_a_perfect_square(), 00204 ["True"]) 00205 00206 check(perfect_square.sqrt().digits_number(), 00207 ["0"]) 00208 00209 check(integer_value.is_an_integer(), 00210 ["True"]) 00211 00212 check(one_digit_value.is_an_integer(), 00213 ["False"]) 00214 00215 check(perfect_decimal_square.is_a_perfect_square(), 00216 ["True"]) 00217 00218 check(two_digits_value.is_a_perfect_square(), 00219 ["False"]) 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234