x12117137 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/x12117137.rb +31 -0
- data/rakefile +6 -0
- data/test/test_x12117137.rb +75 -0
- metadata +48 -0
data/lib/x12117137.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
class Filteranddiscount
|
2
|
+
def self.runfilter(txt)
|
3
|
+
blockedWords = ["fucking","shit","stupid","foolish"]
|
4
|
+
blockedWords.each { |x|
|
5
|
+
if txt.include? x
|
6
|
+
txt.gsub!(x, "****")
|
7
|
+
end
|
8
|
+
}
|
9
|
+
|
10
|
+
return txt
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.rundiscount(discount,price)
|
14
|
+
if discount=="10% off"
|
15
|
+
price=price/10*9
|
16
|
+
else if discount=="20% off"
|
17
|
+
price=price/10*8
|
18
|
+
else if discount=="30% off"
|
19
|
+
price=price/10*7
|
20
|
+
else if discount=="40% off"
|
21
|
+
price=price/10*6
|
22
|
+
else if discount=="half price"
|
23
|
+
price=price/2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return price
|
30
|
+
end
|
31
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'x12117137'
|
3
|
+
class FilterTest < Test::Unit::TestCase
|
4
|
+
# List of example bad words to test
|
5
|
+
# Unit test to see if the code sees fucking is a bad word.
|
6
|
+
def test_fucking
|
7
|
+
assert_equal "You aaa bbb **** ccc",
|
8
|
+
Filteranddiscount.runfilter("You aaa bbb fucking ccc")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Test to see if the code sees shit is a bad word.
|
12
|
+
def test_shit
|
13
|
+
assert_equal "You hhh iii **** jjj",
|
14
|
+
Filteranddiscount.runfilter("You hhh iii shit jjj")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Test if stupid a bad word.
|
18
|
+
def test_stupid
|
19
|
+
assert_equal "You ooo ppp **** qqq",
|
20
|
+
Filteranddiscount.runfilter("You ooo ppp stupid qqq")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Test if foolish a bad word.
|
24
|
+
def test_foolish
|
25
|
+
assert_equal "You rrr sss **** ttt",
|
26
|
+
Filteranddiscount.runfilter("You rrr sss foolish ttt")
|
27
|
+
end
|
28
|
+
|
29
|
+
#test if fucking and stupid a bad word
|
30
|
+
def test_fucking_stupid
|
31
|
+
assert_equal "You xxx **** yyy **** zzz",
|
32
|
+
Filteranddiscount.runfilter("You xxx fucking yyy stupid zzz")
|
33
|
+
end
|
34
|
+
|
35
|
+
#test fucking twice
|
36
|
+
def test_fucking_again
|
37
|
+
assert_equal "You xxx **** yyy **** zzz",
|
38
|
+
Filteranddiscount.runfilter("You xxx fucking yyy fucking zzz")
|
39
|
+
end
|
40
|
+
|
41
|
+
end # End of Class
|
42
|
+
|
43
|
+
class DiscountTest < Test::Unit::TestCase
|
44
|
+
|
45
|
+
def test_10percentoff
|
46
|
+
assert_equal 90,
|
47
|
+
Filteranddiscount.rundiscount("10% off",100)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_20percentoff
|
51
|
+
assert_equal 80,
|
52
|
+
Filteranddiscount.rundiscount("20% off",100)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_30percentoff
|
56
|
+
assert_equal 70,
|
57
|
+
Filteranddiscount.rundiscount("30% off",100)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_40percentoff
|
61
|
+
assert_equal 60,
|
62
|
+
Filteranddiscount.rundiscount("40% off",100)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_halfprice
|
66
|
+
assert_equal 50,
|
67
|
+
Filteranddiscount.rundiscount("half price",100)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_fullprice
|
71
|
+
assert_equal 100,
|
72
|
+
Filteranddiscount.rundiscount("full price",100)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: x12117137
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ming Yuan Yang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This Gem is for WAF Project.
|
15
|
+
email: mingyuan7725@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- rakefile
|
21
|
+
- lib/x12117137.rb
|
22
|
+
- test/test_x12117137.rb
|
23
|
+
homepage: http://rubygems.org/gems/x12117137
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.24
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: filter some bad language and items discount!
|
47
|
+
test_files:
|
48
|
+
- test/test_x12117137.rb
|