specs2でテストでtagをつけて
"hugehuge" in {
//
} tag("a")
指定して実行
package util | |
import org.specs2.mutable._ | |
class BenchmarkSpec extends Specification with Before with Benchmark { | |
def before() = isPrint = false | |
"loop" should { | |
"10 times" in { |
package util | |
import compat.Platform | |
/** | |
* ベンチマーク用trait | |
* | |
* 継承して、loop(ループ回数, 実行するFunction) してあげると | |
* 指定回数実行して、結果がprintされる。 | |
* |
// SeqをMapに | |
// Seq(1,2,3) => Map(1 -> 2, 2 -> 3, 3 -> 4) | |
Seq(1, 2, 3).flatMap { i => | |
Map(i -> (i + 1)) | |
}.toMap | |
// SomeにnullいれてもNoneにはならない | |
Some(null) == None // false | |
Option(null) == None // true |
specs2でテストでtagをつけて
"hugehuge" in {
//
} tag("a")
指定して実行
val pp1 = Seq(1, 2) zip Seq(3, 4) | |
println(pp1) | |
// List((1,3), (2,4)) | |
case class Image(width: Seq[Int], height: Seq[Int]) | |
val images = Seq(Image(Seq(200, 300), Seq(210, 310)), Image(Seq(400, 500), Seq(510, 610))) | |
val pp2 = images.flatMap { b => | |
b.width zip b.height |
abstract class Interface(_id: Int) { | |
def id: Int = _id | |
} | |
trait Like { | |
self : Interface => | |
def get: Int = this.id | |
} | |
trait Param { |
/** | |
* Parse query string. | |
* ?a=b&c=d to {a: b, c: d} | |
* @param {String} (option) queryString | |
* @return {Object} query params | |
*/ | |
getQueryParams: function(queryString) { | |
var query = (queryString || window.location.search).substring(1); // delete ? | |
if (!query) { | |
return false; |
var params = {b: 1, a: 5, c: 2}; | |
_.pick(params, _.keys(params).sort()); // {a: 5, b:1, c:2} |
var obj = {b: 1, a: 3, c:2}; | |
_.map(_.keys(obj).sort(), function(key) { | |
return key + '=' + obj[key]; | |
}).join('&'); | |
// a=3&b=1&c=2 |
/** | |
* $formのデータをkey:valueで取得 | |
* @param {jQuery} $form | |
* @return {Object} {name: "value", ...} | |
*/ | |
getValues: function($form) { | |
return _.chain($form.serializeArray()) | |
.map(function(obj) { return [obj.name, obj.value] }) | |
.object() | |
.value(); |