我有一个非常简单的测试,我试图模拟一个特征.测试甚至没有运行,并且它因初始化错误而失败:java.lang.IllegalArgumentException:要求失败:您是否记得使用withExpectations?
这是我非常简单的测试:
import org.scalatest._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory
@RunWith(classOf[JUnitRunner])
class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory {
trait Turtle {
def turn(angle: Double)
}
val m = mock[Turtle]
m expects 'turn withArgs (10.0)
describe("A turtle-tester") {
it("should test the turtle") {
m.turn(10.0)
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在查看https://github.com/playframework/Play20/tree/master/samples/scala/websocket-chat上的示例
要制作一个websocket控制器,你可以这样写:
def chat(username: String) = WebSocket.async[JsValue] { request =>
ChatRoom.join(username)
}
Run Code Online (Sandbox Code Playgroud)
Chatroom.join返回一个scala.concurrent.Future [(Iteratee [JsValue,_],Enumerator [JsValue])].但是在Play中使用的iteratee和枚举器在哪里!框架?该网页套接字类(WebSocket.scala)似乎忽视了投入:
case class WebSocket[A](f: RequestHeader => (Enumerator[A], Iteratee[A, Unit]) => Unit) (implicit val frameFormatter: WebSocket.FrameFormatter[A]) extends Handler {
type FRAMES_TYPE = A
/**
* Returns itself, for better support in the routes file.
*
* @return itself
*/
def apply() = this
}
Run Code Online (Sandbox Code Playgroud)
怎么玩!在消耗输入时管理iteratee的变化状态?
我正在使用AES的PyCrypto实现,我正在尝试使用24字节密钥加密一些文本(24字节).
aes_ecb = AES.new('\x00'*24, AES.MODE_ECB)
aes_ecb.encrypt("123456"*4)
Run Code Online (Sandbox Code Playgroud)
我得到了这个令人惊讶的错误ValueError: Input strings must be a multiple of 16 in length
那么为什么我的输入必须是16的倍数?对我来说更有意义的是输入字符串长度必须是我的密钥大小的倍数,因为这将允许密钥和明文块之间的良好按位操作.
我想为 Scala 2.11 中的字符串生成非加密哈希码
我在网上查看并找到了一个名为 MurmurHash3 的类,但是当我尝试使用它时,我得到了一个非常无用的 class MurmurHash3 in package hashing cannot be accessed in package scala.util.hashing
为什么我无法访问该包?有替代方案吗?
我正在通过Vagrant/Virtualbox配置的Ubuntu机器上的Typesafe Activator运行SBT.主机是Windows 8.
我正在尝试通过输入命令(或)来编译Play项目https://github.com/markisus/ScalaPoker,然后将repo克隆到计算机上.repo位于同步文件夹中./activatorsudo ./activatorcompile.我认为这是问题的根源.
我收到了错误 Operation not permitted:
[info] Compiling 34 Scala sources to /home/vagrant/sp2/ScalaPoker/ScalaPokerEngine/target/scala-2.11/classes...
[error] Operation not permitted
[error] one error found
[error] (ScalaPokerEngine/compile:compile) Compilation failed
[error] Total time: 91 s, completed Jan 26, 2015 4:29:22 AM
Run Code Online (Sandbox Code Playgroud)
我不确定哪个操作完全不允许.该项目在我的主机上编译得很好.
运行 last,我明白了
[debug] Running cached compiler e13c8f, interfacing (CompilerInterface) with Scala compiler version 2.11.1
[debug] Calling Scala compiler with arguments (CompilerInterface):
[debug] -bootclasspath
[debug] /usr/lib/jvm/java-6-openjdk-i386/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/jfr.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/netx.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/plugin.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk-i386/jre/classes:/root/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar
[debug] -classpath
[debug] /home/vagrant/sp2/ScalaPoker/ScalaPokerEngine/target/scala-2.11/classes
[error] Operation …Run Code Online (Sandbox Code Playgroud) 我有一个 Visual Studio 2017 解决方案和 C++ 项目,其中包含一个名为 Source.cpp 的源文件。在 Source.cpp 中,我#include <FL/Fl.H>显示红色下划线,因为 Visual Studio 找不到它。
在我的文件系统上,我已验证该文件c:\fltk\include\FL\Fl.H存在,然后右键单击我的项目并将目录添加c:\fltk\include到项目中Include Directories。
如何让 Visual Studio 2017 包含该文件?
这太令人沮丧了!我不知道为什么会这样.我有一个名为weirdDLL.c的文件:
double five() {
return 5.0;
}
Run Code Online (Sandbox Code Playgroud)
我有另一个名为weirdTest.c的文件
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double f = five();
if (f != 5.0) {
printf("Test failed with %f", f);
return 1;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我希望,当编译并与DLL链接时,weirdTest中的代码将无错误地退出.我正在64位Windows 7上使用gcc(cygwin)编译命令:
gcc -c weirdDLL.c
gcc -shared -o weirdDLL.dll weirdDLL.o
gcc -o test weirdtest.c -L./ -l weirdDLL
./test
Run Code Online (Sandbox Code Playgroud)
输出是:
Test failed with 0.000000
Run Code Online (Sandbox Code Playgroud)
似乎DLL正在正确链接,因为编译器不会抱怨缺少函数"五".另外,当我在DLL代码中放置print语句时,它们显示正常.我做错了什么?
基本上我想这样:在 Mustache 模板中,是否有一种优雅的方式来表达没有尾随逗号的逗号分隔列表?在 Ractive 模板中。
对于对象
{
"items": [
{"name": "red"},
{"name": "green"},
{"name": "blue"}
]
}
Run Code Online (Sandbox Code Playgroud)
我想产生“红,绿,蓝”
我想知道我是否在最后一项,所以我可以知道是否打印分隔符。就像是:
{{#items:i}}{{name}} {{#i.is_last}},{{/i}}{{/items}}
Run Code Online (Sandbox Code Playgroud) 我正在阅读http://dev.twitter.com/pages/auth上的演练,但编码回调URL时似乎存在不一致.回调列为:
oauth_callback - http:// localhost:3005/the_dance/process_callback?service_provider_id = 11
签名基本字符串列为:
POST&... oauth_callback%3D http%253A%252F%252Flocalhost%253A3005%252Fthe_dance%252Fprocess_callback%253Fservice_provider_id%253D11%26oauth_consumer_key%3D ...
这里的回调似乎是双重编码的.
签名的授权标题列为:
OAuth oauth_nonce ="QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk",oauth_callback =" http%3A%2F%2Flocalhost%3A3005%2Fthe_dance%2Fprocess_callback%3Fservice_provider_id%3D11 ",...
这里,回调似乎是单个URL编码.为什么他们不一致?
在C++库glog(Google日志记录模块)中,有一个很好的界面,您可以在其中编写
LOG(INFO) << "abc " << my_var;
并且在运行时它会在运行时打印abc 5\n(如果my_var为5),它会自动以换行符结束.
这是远优于不必总是终止std::endl在
std::cout << "abc " << my_var << std::endl;
什么是最简单的方法(代码+宏)我需要在我的代码中复制这种效果?
这可能是由于我对 Squeryl 的工作方式的误解。我的实体定义为:
case class Wallet(userid: Int, amount: Long)
extends KeyedEntity[Int] with Optimistic {
def id = userid
}
Run Code Online (Sandbox Code Playgroud)
我的表变量定义为:
val walletTable = table[Wallet]("wallets")
on(walletTable) {
w =>
declare {
w.userid is (primaryKey)
}
}
Run Code Online (Sandbox Code Playgroud)
然后我只是调用一个方法来尝试向钱包中添加钱:
val requestedWallet = wallet.copy(amount = wallet.amount + amount)
try {
inTransaction {
walletTable.update(requestedWallet)
}
Run Code Online (Sandbox Code Playgroud)
在我调用更新的那一行,抛出一个异常: [ClassCastException: java.lang.Integer cannot be cast to org.squeryl.dsl.CompositeKey]
我根本没有使用复合键,所以这很令人困惑。这是否与我的 id 字段不被称为“id”,而是“userid”这一事实有关?
在程序的一部分中,我以两种不同的方式打印出相同的指针。
vpx_codec_iface_t *ptr = vpx_codec_vp9_cx();
printf("ptr1 %p\n", ptr);
printf("ptr2 %p\n", vpx_codec_vp9_cx());
Run Code Online (Sandbox Code Playgroud)
这奇怪地导致以下输出。
ptr1 FFFFFFFFDAF9CED0
ptr2 00000000DAF9CED0
Run Code Online (Sandbox Code Playgroud)
玩弄这个程序,我可以通过添加一些代码或添加一些换行符来“修复”错误。
int x = 0;
vpx_codec_iface_t *ptr = vpx_codec_vp9_cx();
printf("ptr1 %p\n", ptr);
printf("ptr2 %p\n", vpx_codec_vp9_cx());
printf("x=%d\n", x);
Run Code Online (Sandbox Code Playgroud)
这导致以下输出。
ptr1 0000000066A7CED0
ptr2 0000000066A7CED0
x=0
Run Code Online (Sandbox Code Playgroud)
什么可能导致这种行为?我在 Windows 10 上使用 Visual Studio 2019 编译器,为 x64 进行编译。函数调用vpx_codec_vp9_cx()是在vpxmd.lib其中实现的,来自libvpx项目。
编辑:我仍在查看您的答案和评论,但我在下面创建了一个最小示例。不幸的是,它涉及构建整个 vpx 库,因此我需要一些时间来简化该部分。
#include <stdio.h>
#include "vpx/vpx_encoder.h"
int main(int argc, char **argv) {
printf("This is main\n");
vpx_codec_iface_t *ptr = vpx_codec_vp9_cx();
int x = 0;
printf("ptr1 …Run Code Online (Sandbox Code Playgroud)