假设我的familyTree.pl文件中包含以下代码:
male(tom).
male(bob).
female(lisa).
female(emily).
parent(tom, bob).
parent(lisa, bob).
morethanfriends(emily, bob).
father(X,Y) :- male(X), parent(X,Y).
mother(X,Y) :- female(X), parent(X,Y).
girlfriend(X,Y) :- female(X), (morethanfriends(X,Y); morethanfriends(Y,X)).
boyfriend(X,Y) :- male(X), (morethanfriends(X,Y); morethanfriends(Y,X)).
Run Code Online (Sandbox Code Playgroud)
现在,我想获得以下问题的答案:
What is the relationship between Tom and Bob ?
What is the relationship between Lisa and Emily ?
Run Code Online (Sandbox Code Playgroud)
我怎样才能问上述问题做序?
我唯一能想到的解决方案是遍历已知的关系类型,将(Tom,Bob)或(Lisa,Emily)用作参数,并检查哪个返回true。但; 当已知关系类型的数量超过少数并且/或者给定的两个人之间存在链式关系时(例如:Lisa和Emily:Lisa是Emily的男朋友的母亲),这种解决方案似乎是在浪费时间。
我使用Jest来测试我的React组件.但是,我不知道(或者没有看到任何东西)如何测试将方法传递给子组件的组件(作为prop).举例来说,我有:Form,MemberList,Member,FormButton.代码中与此类似的东西:
形成:
<MemberList members={this.state.members} remove={this.remove} add={this.add} />
<FormButton data={this.state.members} />
Run Code Online (Sandbox Code Playgroud)
会员:
<span onClick={this.add}> <!-- add button --> </span>
{this.props.members.map(function(member, index) {
<Member key={index} data={member} remove={this.props.remove} />
})}
Run Code Online (Sandbox Code Playgroud)
会员:
// some input like name and so, and a remove itself button.
Run Code Online (Sandbox Code Playgroud)
FormButton:
var submit = function() {
this.setState({ loading: true });
// xhr
}
<button type="button" onClick={submit} disabled={this.state.loading}>Submit</button>
Run Code Online (Sandbox Code Playgroud)
我是否以正确的心态思考?补充一点,那里有实际的例子吗?
*在尝试React和Jest之前,我从未测试过.
如何使用Mono和C#从video-4-linux设备(例如:/ dev/video0)捕获帧?操作系统是在BeagleBoard上运行的Angstrom Linux.
我使用带有require()的CommonJS模块,除了React,它是全局的:
// I don't want require React in every module:
// var React = require("react");
var MyComponent = React.createClass({ // React is global here
});
Run Code Online (Sandbox Code Playgroud)
在MyComponent上运行单元测试时,Jest无法找到React.有没有办法告诉Jest插入一个全局的React对象?(我使用npm和gulp-browserify.)
试图运行Jest测试React代码的例子(来自https://github.com/facebook/jest/tree/master/examples/react),我收到以下错误:
> @ test /home/aizquier/jest/examples/react
> jest
Using Jest CLI v0.7.1
FAIL __tests__/CheckboxWithLabel-test.js
? Runtime Error
SyntaxError: /home/aizquier/jest/examples/react/__tests__/CheckboxWithLabel-test.js: Unexpected token (15:6)
npm ERR! Test failed. See above for more details.
Run Code Online (Sandbox Code Playgroud)
测试在文件CheckboxWithLabel-test.js的第15行失败:
jest.dontMock('../CheckboxWithLabel');
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
const CheckboxWithLabel = require('../CheckboxWithLabel');
describe('CheckboxWithLabel', function() {
it('changes the text after click', function() {
// Render a checkbox with label in the document
var checkbox = TestUtils.renderIntoDocument(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
var checkboxNode …Run Code Online (Sandbox Code Playgroud) 有没有办法触发标签error事件img来测试我的onError回调?例如,给定这个组件,
import React from 'react';
/**
* Self removing <img> when the `src` or image
* does not load or is unavailable.
*
* Usage: (tip: it's how you use the <img> tag, basically)
* <Img src={} alt={} ../..>
*/
var Img = React.createClass({
/**
* Force update so `refs` will be available
*/
componentDidMount() {
this.forceUpdate();
},
render() {
// Omit any passed `onError` prop so that
// it is never overridden by …Run Code Online (Sandbox Code Playgroud) 我正在使用Ruby在基于ARM的嵌入式主板上开发一个商业项目,其上有一个定制的Linux内核.项目的目标工作区和设备是一个封闭的环境,没有以太网,inernet,I/O设备等......我想保护我的代码/程序,以便; 它只能在我允许的特定机器上工作(所以;人们不能将我的代码/程序复制并粘贴到他们的嵌入式主板上并在没有权限的情况下运行它).这可以通过机器的MAC地址来完成; 我对这个问题没有任何经验.我想,只是一个简单的if(device.MACAddr =="XX:XX ...... XX")不会被删除(更不用说人们可以轻松地从我的代码中删除支票).我不能使用一些红宝石混淆器,我通过谷歌发现,因为; 设备不运行ruby-external-C-libraries或类似东西,只有纯ruby代码.
所以; 你有什么建议,我应该采取什么样的方法?
有没有办法给特定的酒吧着色?如果条形小于线条,则将其着色为红色.
代码:https://github.com/tvinci/webs/blob/gh-pages/lineplusbar.html
示例:http://tvinci.github.io/webs/lineplusbar.html
我想做这样的事情,但i的值不是我发送的y值.它已被修改:
d3.selectAll("rect.nv-bar")
.style("fill", function(d, i){
return i > 50 ? "red":"blue";
});
Run Code Online (Sandbox Code Playgroud)
数据:
var overview_data=[
{
"key" : "Achieved",
"bar": true,
"values" : [ [ "1x" , 30] , [ "2x" , 70] , [ "3x" , 200] ]
},
{
"key" : "Required",
"values" : [ [ "1x" , 50] , [ "2x" , 100] , [ "3x" , 150] ]
}
].map(function(series) {
series.values = series.values.map(function(d) { return {x: …Run Code Online (Sandbox Code Playgroud) 我正在阅读Java™I/O,第2版这本书,这里有以下代码:
try {
byte[] b = new byte[10];
System.in.read(b);
}
catch (IOException ex) {
System.err.println("Couldn't read from System.in!");
}
Run Code Online (Sandbox Code Playgroud)
从书中引用:
"..没有什么可以阻止你尝试将更多数据读入数组而不是适合.如果你这样做,read()抛出一个ArrayIndexOutOfBoundsException .."
但是,当我运行此代码并输入超过10个字符时,不会ArrayIndexOutOfBoundsException抛出; 为什么会这样?
javascript ×4
jestjs ×4
reactjs ×4
testing ×2
.net ×1
beagleboard ×1
c# ×1
d3.js ×1
exception ×1
family-tree ×1
java ×1
linux ×1
mono ×1
node.js ×1
nvd3.js ×1
prolog ×1
ruby ×1
security ×1
svg ×1
unit-testing ×1