小编use*_*764的帖子

为什么 MVC 中的单元测试比 MVP 和 MVVM 更难

我一直在研究 MVC/MPV/MVVM 的优缺点,一个共同的主题是 MVC 比 MVP 和 MVVM 更难进行单元测试,但我不完全理解为什么。

根据我目前的理解,在 MVC 中,视图依赖于模型和控制器,因此要测试视图,必须模拟控制器和模型。MVP/MVVM 如何改进?

model-view-controller mvp android mvvm android-mvvm

7
推荐指数
2
解决办法
658
查看次数

使用reduce查找最大值

新的clojure与java背景.我有下表,需要将表转换为哈希映射,将产品映射到销售额最高的城市.例如,输出应如下所示:

{"Pencil": "Toronto"
"Bread": "Ottawa"}

(def table [
    {:product "Pencil"
    :city "Toronto"
    :year "2010"
    :sales "2653.00"}
    {:product "Pencil"
    :city "Oshawa"
    :year "2010"
    :sales "525.00"}
    {:product "Bread"
    :city "Toronto"
    :year "2010"
    :sales "136,264.00"}
    {:product "Bread"
    :city "Oshawa"
    :year "nil"
    :sales "242,634.00"}
    {:product "Bread"
    :city "Ottawa"
    :year "2011"
    :sales "426,164.00"}])
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止:

(reduce (fn [product-cities {:keys [product sales]}]
         (update-in product-cities [product] (fnil conj []) sales))
       {}
       table)
Run Code Online (Sandbox Code Playgroud)

这产生了结果:

{"Bread"
["136,264.00"
"242,634.00"
"426,164.00"],
 "Pencil" ["2653.00" "525.00"]}
Run Code Online (Sandbox Code Playgroud)

我如何比较每个城市的销售情况,并且只保留销售额最高的城市名称?对此非常艰难.谢谢

clojure

2
推荐指数
1
解决办法
401
查看次数

哈希映射不显示为哈希映射

新的clojure.尝试使用java后台解决以下问题.我需要将表转换为哈希映射,将产品映射到销售产品的所有城市.所以输出应该是.

{"Pencil": ("Oshawa" "Toronto")
 "Bread": ("Ottawa" "Oshawa" "Toronto")}


(def table [
        {:product "Pencil"
        :city "Toronto"
        :year "2010"
        :sales "2653.00"}
        {:product "Pencil"
        :city "Oshawa"
        :year "2010"
        :sales "525.00"}
        {:product "Bread"
        :city "Toronto"
        :year "2010"
        :sales "136,264.00"}
        {:product "Bread"
        :city "Oshawa"
        :year "nil"
        :sales "242,634.00"}
        {:product "Bread"
        :city "Ottawa"
        :year "2011"
        :sales "426,164.00"}])
Run Code Online (Sandbox Code Playgroud)

这就是我到目前为止所拥有的.我把这段代码写入repl.

(let [product-cities {}]
(for [row table]
  (if (= (contains? product-cities (keyword (row :product))) true)
    (println "YAMON") ;;To do after. Add city to product if statement is true
    (into …
Run Code Online (Sandbox Code Playgroud)

clojure

1
推荐指数
1
解决办法
162
查看次数