From: Jean-Julien Fleck on
Hello Alex,

> Yes, there has to be some additional logic to allow a trailing 'e' with
> the assumption that the user will next enter a valid character
> afterward.  That's what makes it a little complicated (and fun) to
> figure out.  The goal is, as the user is entering data, to not allow
> them to enter anything that is obviously not going to work as a floating
> point representation.

Sure, fun it is :o)
But that's exactly the kind of software that could drive me mad (as a
user). You assume that your user is making a typo but what if he is
not ? What if he truly believe what he is writing is a perfectly
correct float ? He will retry again, and again and again untill he
decide that the whole software is just a fraud :o) So IMHO, it is more
efficient to let your user know what kind of error he is (possibly
repetitively) doing and propose an alternative rather than erase what
he believe could be right.

Cheers,

--
JJ Fleck
PCSI1 Lycée Kléber

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Wed, Apr 14, 2010 at 8:33 AM, Alex DeCaria <alex.decaria(a)millersville.edu
> wrote:

> Josh Cheek wrote:
> > This is what I have so far, please check and correct any tests that
> > should
> > be different
>
> Josh,
>
> Your code works great! I knew there had to be a more elegant way to do
> this rather than my brute force method.
>
> The only test it didn't seem to work on was eliminating extra + or -
> signs, such as '+45-2+8' => '+4528', but now that I see what you are
> doing I can probably figure out how to do that. I definitely need to
> learn more about regular expressions!
>
> Thanks for your time and effort.
>
> --Alex
> --
> Posted via http://www.ruby-forum.com/.
>
>
It wasn't done, because I wanted clarification on the tests first.

Anyway, this one passes all tests.

def clean_string(str)
str =~ /\A([-+]?)([eE]?)([^eE.]*\.?)([^eE]*)((?:[eE][+-]?)?)([^Z]*)\Z/
posneg , misplaced_e , before_dec , after_dec , e , exponent = $1 , $2 ,
$3 , $4 , $5 , $6
posneg + before_dec.gsub(/[^0-9.]/,'') + after_dec.gsub(/[^0-9]/,'') + e +
exponent.gsub(/[^0-9]/,'')
end

require 'test/unit'
class TestCleanString < Test::Unit::TestCase
def test_delete_chars
assert_equal '-24.5e45' , clean_string('-24.5fge4x5')
end
def test_delete_extra_decimal
assert_equal '2.45' , clean_string('2.4.5')
assert_equal '2.45' , clean_string('2..45')
assert_equal '2.45' , clean_string('2...45')
end
def test_delete_extra_decimal_in_exponent
assert_equal '245e76' , clean_string('245e7.6')
end
def test_delete_extra_or_misplaced_pos_and_neg_signs
assert_equal '+4568e+45' , clean_string('+45-68+e+45-')
end
def test_delete_extra_or_misplaced_e_or_E
assert_equal '4.67e67' , clean_string('4.67e6e-7')
assert_equal '+4.67e-7' , clean_string('+e4.67e-7')
end
end

From: Alex DeCaria on
Josh Cheek wrote:
> On Wed, Apr 14, 2010 at 8:33 AM, Alex DeCaria
> <alex.decaria(a)millersville.edu
>> wrote:
>
>> The only test it didn't seem to work on was eliminating extra + or -
>>
> It wasn't done, because I wanted clarification on the tests first.
>
> Anyway, this one passes all tests.
>
Thanks again, Josh! May I use your code in my (non-commercial,
educational-use-only) app?

--Alex
--
Posted via http://www.ruby-forum.com/.

From: Alex DeCaria on
Jean-Julien Fleck wrote:

>
> Sure, fun it is :o)
> But that's exactly the kind of software that could drive me mad (as a
> user). You assume that your user is making a typo but what if he is
> not ? What if he truly believe what he is writing is a perfectly
> correct float ? He will retry again, and again and again untill he
> decide that the whole software is just a fraud :o) So IMHO, it is more
> efficient to let your user know what kind of error he is (possibly
> repetitively) doing and propose an alternative rather than erase what
> he believe could be right.
>
> Cheers,

I can't argue with the point you are making. I will continue to use the
automatic string grooming, but will probably include a message to the
user letting them know why what they are typing isn't showing up in the
textbox.

--Alex
--
Posted via http://www.ruby-forum.com/.

From: Josh Cheek on
[Note: parts of this message were removed to make it a legal post.]

On Wed, Apr 14, 2010 at 10:06 AM, Alex DeCaria <
alex.decaria(a)millersville.edu> wrote:

> Josh Cheek wrote:
> > On Wed, Apr 14, 2010 at 8:33 AM, Alex DeCaria
> > <alex.decaria(a)millersville.edu
> >> wrote:
> >
> >> The only test it didn't seem to work on was eliminating extra + or -
> >>
> > It wasn't done, because I wanted clarification on the tests first.
> >
> > Anyway, this one passes all tests.
> >
> Thanks again, Josh! May I use your code in my (non-commercial,
> educational-use-only) app?
>
> --Alex
> --
> Posted via http://www.ruby-forum.com/.
>
>
Sure, go ahead and throw the wtfpl on there, if you feel more comfortable
with that. http://sam.zoy.org/wtfpl/

And I guarantee that it does nothing other than pass the set of tests it was
posted with, on my machine, with the settings that were used at the time of
testing. So no warranty of any kind.

Have fun :P

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: [ANN]VTD-XML 2.8
Next: Rorth v0.3 released