#1 楼 @blacktulip 你歪楼了
不如考 FizzBuzz,谁答案字符数最少就选谁
#19 楼 @blacktulip 他把小数点往后挪了一位吧,就差乘以 pi 了
和 x 被定义成什么都关系
irb(main):001:0> def x
irb(main):002:1> 1
irb(main):003:1> end
=> nil
irb(main):004:0> x +"\n"
NoMethodError: undefined method `+@' for "\n":String
from (irb):4
from /usr/bin/irb:12:in `<main>'
特别是 + 前面是 method 的情况,无论这个 method 是否有定义都可以重现。
irb(main):001:0> class X
irb(main):002:1> def y
irb(main):003:2> 1
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> x = X.new
=> #<X:0x000000021b3670>
irb(main):007:0> x.y +"\n"
NoMethodError: undefined method `+@' for "\n":String
from (irb):7
from /usr/bin/irb:12:in `<main>'
看来你们都不会 Ruby 啊
悲剧了,erlang 的 dict 竟然不自带比较,还得自己写一个
word_count(S) ->
lists:foldl(
fun (W, D) -> dict:update_counter(W, 1, D) end,
dict:new(),
string:tokens(string:to_lower(S), " ~!@#$%^&*:,.")).
dict_equal(D1, D2) ->
D3 = dict:merge(fun (_,V1,V2) -> V1 = V2 end, D1, D2),
true = dict:size(D3) == dict:size(D1).
test(count_one_word) ->
dict_equal(
word_count("word"),
dict:from_list([{"word", 1}]));
test(count_one_of_each) ->
dict_equal(
word_count("one of each"),
dict:from_list([{"one", 1}, {"of", 1}, {"each", 1}]));
test(count_multiple_occurrences) ->
dict_equal(
word_count("one fish two fish red fish blue fish"),
dict:from_list([{"one", 1}, {"fish", 4}, {"two", 1}, {"red", 1}, {"blue", 1}]));
test(ignore_punctuation) ->
dict_equal(
word_count("car : carpet as java : javascript!!&@$%^&"),
dict:from_list([{"car", 1}, {"carpet", 1}, {"as", 1}, {"java", 1}, {"javascript", 1}]));
test(handles_cramped_lists) ->
dict_equal(
word_count("one,two,three"),
dict:from_list([{"one", 1}, {"two", 1}, {"three", 1}]));
test(include_numbers) ->
dict_equal(
word_count("testing, 1, 2 testing"),
dict:from_list([{"testing", 2}, {"1", 1}, {"2", 1}]));
test(normalize_case) ->
dict_equal(
word_count("go Go GO"),
dict:from_list([{"go", 3}])).
test() ->
test(count_one_word),
test(count_one_of_each),
test(count_multiple_occurrences),
test(ignore_punctuation),
test(handles_cramped_lists),
test(include_numbers),
test(normalize_case),
ok.
#49 楼 @blacktulip 同问
感觉你的代码写得挺好的,测试却写得好坑爹啊,明明一个函数搞定的,非要整个类啊
被test_count_everything_just_once
这个测试雷翻了,代码要写得多坑爹才会出这种问题啊。
桌面当然用 Linux 啊
#3 楼 @blacktulip 你表白了几次?
#67 楼 @benzheren 有个问题,为啥 General XXX 和语音识别/机器学习不能全职?