小编Abr*_*m P的帖子

如何测试依赖于ngResource服务的Controller

我有一个控制器,它依赖于通过ngResource构建的服务.我在测试时遇到了麻烦(尽管两者在实际应用中似乎都很有魅力).以下是(已消毒的)控制器

MyApp.Controller.MyCarsController = (scope, http, typeService) ->
  if scope.context==undefined
    scope.ferrari_or_porshe =""
    scope.id = ""
  else if scope.context=="ferrari"
    scope.country_or_pi ="Ferrari"
  else if scope.context=="porshe"
    scope.country_or_pi ="Porshe"

  typeService.index
    ferrari_or_porshe: scope.ferrari_or_porshe
    id: scope.id
  , (response) ->
    scope.type = response
    scope.loading = false

MyApp.Controller.MyCarsController.$inject = ['$scope', '$http', 'Type']
Run Code Online (Sandbox Code Playgroud)

这就是服务:

MyApp.MyModule.factory 'Type', ['$resource', ($resource) ->
  TypeResource = $resource("/api/types/:ferrari_or_porshe/:id", {},
    index:
      method: "GET"
      isArray: true
  )
  return TypeResource
]
Run Code Online (Sandbox Code Playgroud)

最后,一些测试代码:

describe 'MyApp.Controller.MyCarsController', ->
  beforeEach module('MyModule')
  beforeEach inject ($rootScope, $http, $controller, Type) ->
    @scope = $rootScope.$new()
    @typeService = …
Run Code Online (Sandbox Code Playgroud)

coffeescript jasmine angularjs

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

Yesod二进制不可用

我从这里安装了Mac OS X Haskell PLatform:

http://www.haskell.org/platform/mac.html

 > which ghc
   /usr/bin/ghc
 > which ghci
   /usr/bin/ghci
 >cabal update
   -----
 >cabal install cabal-install
   -----
 >cabal install yesod
   -----
 >yesod init
   -bash: yesod: command not found
 >which yesod
 >ghc-pkg list
   ....
   yesod-1.2.5.2
   yesod-auth-1.3.0.4
   yesod-core-1.2.13
   yesod-form-1.3.8.2
   yesod-persistent-1.2.2.3
   yesod-routes-1.2.0.6
Run Code Online (Sandbox Code Playgroud)

为什么cabal无法创建yesod二进制文件?如何修复此安装?如何检查yesod的安装位置以手动创建符号链接?

macos haskell cabal yesod

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

我的功能测试二元搜索树的成员资格有什么问题?

可以说我有以下数据类型:

data BinaryTree a = EmptyTree | Node a (BinaryTree a) (BinaryTree a) deriving (Eq, Ord, Show)

以及以下功能

  member a EmptyTree = False
  member a (Node x l r)
    | a < x = member a l
    | a > x = member a r
    | a == x = True
Run Code Online (Sandbox Code Playgroud)

这个功能有效.

检查类型Node:

:t Node
Node :: a -> BinaryTree a -> BinaryTree a -> BinaryTree a
Run Code Online (Sandbox Code Playgroud)

但是,如果成员函数具有签名: member :: Node a -> BinaryTree a -> Bool

( …

membership haskell types binary-search-tree

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

使用 Hardhat 通过 Uniswap 流动性配置测试代币

我正在尝试分叉 Safemoon(或者实际上是 NotSafeMoon),并将其用作学习智能合约开发的工具。(我拥有大量您可能称之为“Web 2.0”的开发经验)。

假设我的构造函数中有类似的内容:

constructor () {
        _rOwned[_msgSender()] = _rTotal;
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);       // binance PANCAKE V2
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,npx hardhat test出现以下失败:

Compilation finished successfully


  TestToken contract
    Deployment
      1) "before each" hook for "Has the right name"


  0 passing (807ms)
  1 failing

  1) TestToken contract
       "before each" hook for "Has the right name":
     Error: Transaction reverted: function call to a non-contract account
Run Code Online (Sandbox Code Playgroud)

现在,这确实很有意义,毕竟我正在尝试调用 Pancakeswap v2 路由器合约。我如何绕过这个限制?有没有办法将路由器的合约地址作为环境变量注入?我可以使用 UniswapRouter 的模拟构造函数吗?一般来说,这种事情是如何通过智能合约开发以保持可测试的方式完成的(以及如何测试)?

testing solidity smartcontracts hardhat

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

如何更新git fork?

可能重复:
我可以在git上将分叉项目更新为原始/主副本吗?

假设我分叉一个项目,然后将其克隆到我的机器上.

此时git pull,以及git fetch和git rebase origin/branch_name,请参阅我的分叉存储库.如果我想重新绑定到原始存储库的主服务器,我将如何进行此操作?

git github git-fork

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

Haskell产生非穷举模式错误

所以我决定玩Haskell.我试图解决项目欧拉的第一个问题.以下是我的代码:

     euler1 limit (div:divisors) = if limit > 1 then (euler1 limit divisors) + (euler1 limit (div:[])) + (euler1 (limit-1) (div:divisors)) else 0
     euler1 limit (divisor:[]) = if limit > 1 && (mod limit divisor) == 0 then limit else 0
     euler1 limit [] = 0
Run Code Online (Sandbox Code Playgroud)

但是,当我通过ghci运行时,会发生以下情况:

     euler1 9 [3,5]
     *** Exception: <interactive>:3:5-90: Non-exhaustive patterns in function euler1
Run Code Online (Sandbox Code Playgroud)

进一步调试:

     euler1 5 []
     0

     euler1 5 [5]
     *** Exception: <interactive>:3:5-90: Non-exhaustive patterns in function euler1
Run Code Online (Sandbox Code Playgroud)

这表明破坏的代码在第二种情况下(带有一个元素的列表),其中euler1甚至不包含递归步骤.

这是怎么回事?为什么它如此惊人地破碎?我错过了什么模式?(我有单个元素列表,多元素列表和空列表没有?)

编辑:对于任何关心我最初提供的解决方案的人(使用John Ls精彩的帮助)仍然不太正确,因为它会计算多于一个除数的倍数的项目.最终的,正确的,有效的算法如下:

       euler1 limit …
Run Code Online (Sandbox Code Playgroud)

haskell

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

Haskell不能构造无限类型:a0 = [a0]

我试图使用Haskell解决Project Euler上的第二个问题.问题是相当直接的 - 将偶数斐波那契数量总和小于4000000.(我是强迫症,我正在暗示一个稍微修改过的函数 - 一个允许任意限制的函数).

我的初始代码是:

euler2 limit (num1:num2) 
    |(num1>limit) = 0
    |((num2>limit) && ((mod num1 2) == 0)) = num1
    |(num2>limit) = 0
    |(((mod num1 2) == 0) && ((mod num2 2) == 0)) = num1+num2+(euler2 limit [num1+num2,num1+num2+num2])
    |((mod num1 2) == 0) = num1+(euler2 limit [num1+num2,num1+num2+num2])
    |((mod num2 2) == 0) = num2+(euler2 limit [num1+num2,num1+num2+num2])
    |otherwise = euler2 limit [num1+num2,num1+num2+num2]
euler2 limit [] = euler2 limit [1,2]
Run Code Online (Sandbox Code Playgroud)

其中产生了以下错误:

Occurs check: cannot construct the infinite type: a0 = …
Run Code Online (Sandbox Code Playgroud)

haskell

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

迭代地打印List中的每个整数

假设我有一个整数列表 l = [1,2]

我要打印到哪个stdout.

做print l产品[1,2]

说我想打印没有大括号的列表

map print l 产生

No instance for (Show (IO ())) arising from a use of `print'
Possible fix: add an instance declaration for (Show (IO ()))
In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)

`:打印

print :: Show a => a -> IO ()
Run Code Online (Sandbox Code Playgroud)

因此,虽然我认为这可行,但我继续尝试:

map putStr $ map show l
Run Code Online (Sandbox Code Playgroud)

因为我怀疑从Integer到String的类型不匹配是罪魁祸首.这产生了与上面相同的错误消息.

我意识到我可以做一些事情,比如将列表连接成一个字符串,但我想尽可能避免这种情况.

这是怎么回事?如何在不从List的元素构造字符串的情况下执行此操作?

haskell ghc ghci

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

在ElasticSearch中对嵌套对象进行通配符搜索

假设我们在以下结构中存储了类型为vehicle的对象,这些对象引用了类型所有者。然后运行以下请求:

`POST:本地主机:9200/15 / vehicles / _search'

具有以下主体:

 { "query": { "wildcard": {"make":"*toy*"} }}
Run Code Online (Sandbox Code Playgroud)

返回相关对象:

     "took": 5,
     "timed_out": false,
     "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
     },
    "hits": {
        "total": 1,
    "max_score": 1,
    "hits": [
        {
            "_index": "15.index",
            "_type": "vehicle",
            "_id": "352",
            "_score": 1,
            "_source": {
                "id": "352",
                "name": "toyota",
                "owner_id": "12",
                "owner": {
                    "id": "12",
                    "name": "John Smith",
                    "login_id": 1,
                    "active": true,
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我现在正在尝试通过嵌套对象(例如,属于用户John Smith的所有车辆)进行查询

 {"query": {"wildcard": {"owner.name": "*John*"}}}
Run Code Online (Sandbox Code Playgroud)

不返回任何结果,而:

 {"query": {"wildcard": {"owner": {"name": "*John*"}}}} …
Run Code Online (Sandbox Code Playgroud)

elasticsearch

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

ReasonML访问JS记录字段

假设我有一个名为 的全局对象Example,它有一个构造函数,该构造new Example()函数返回一个带有名为 的键的对象"Messaging"

假设我有以下原因/Bucklescript 代码:

[@bs.deriving abstract] type example = {
  [@bs.as "Messaging"] messaging: string
};

type wrappedExample = Js.t(example);

[@bs.new] external exampleConstructor: unit => wrappedExample = "ExampleThing";

exampleConstructor()#messaging;
Run Code Online (Sandbox Code Playgroud)

这导致:

This expression has type wrappedExample
It has no method messaging
Run Code Online (Sandbox Code Playgroud)

将最后一行更改为:

exampleConstructor()##messaging或exampleConstructor().messaging同样失败。这里有什么问题呢?我如何访问我的 javascript 值?

https://reasonml.github.io/en/try?rrjsx=true&reason=NoAQRgzgdAJgpgJwJYDckDsDmACAhpAFwVwGMCBdbAgTwAc5s4APXAW1oBsGBebAbwBQ2bKEhRcEbACIAsnAgRcmDJimVW8xcqwAubBCIqBAXwDcAgTXrYA7sVr0YAURb su2XgCloBABTM2TjgaASnMBUWh0OBtKZgJEdFwORlcggGEAe3QDBABXMgyEPVz0JAIPAD5be0cXQPdeKTq3OAAVAAsVKTCAlszsonyCQt9ggGINBSUVUyA

javascript ocaml reason bucklescript

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