小编bre*_*top的帖子

Swift - 单元测试私有变量和方法

我正在尝试测试一个课程,但我对测试什么感到困惑.这是我要进行单元测试的类:

class CalculatorBrain {

    private var accumulator = 0.0

    func setOperand(operand: Double) {
        accumulator = operand
    }

    var result: Double {
        return accumulator
    }

    private var operations: Dictionary<String, Operation> = [
        "=" : .Equals,

        "?" : .Constant(M_PI),
        "e" : .Constant(M_E),

        "±" : .UnaryOperation({ (op1: Double) -> Double in return -op1 }),
        "?" : .UnaryOperation(sqrt ),
        "cos": .UnaryOperation(cos),

        "+" : .BinaryOperation({ (op1: Double, op2: Double) -> Double in return op1 + op2 }),
        "?" : .BinaryOperation({ (op1: Double, op2: Double) -> …
Run Code Online (Sandbox Code Playgroud)

unit-testing swift

36
推荐指数
4
解决办法
2万
查看次数

在 Material UI 中,&amp; 号后面的空格和没有空格有什么区别?

你能解释一下&号后面有空格和没有空格有什么区别吗

例如

您能否解释一下为什么 & label.Mui-focused 中的 & 符号后面有一个空格,而 &.Mui-focused fieldset 中没有空格

const WhiteBorderTextField = styled(TextField)`
  & label.Mui-focused {
    color: white;
  }
  & .MuiOutlinedInput-root {
    &.Mui-focused fieldset {
      border-color: white;
    }
  }
`;
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui jss

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

Swift编译错误 - 表达式太复杂,无法在合理的时间内解决

我正在制作一个非常简单的计算器,我得到一个非常奇怪的编译时错误.我在CalculatorBrain班上遇到以下错误:

表达太复杂,无法在合理的时间内解决; 考虑将表达式分解为不同的子表达式

这是生成错误的代码

private var operations: Dictionary<String, Operation> = [
    "?" : .Constant(M_PI),
    "±" : .UnaryOperation({ -$0 }),
    "×" : .BinaryOperation({ $0 * $1 }),
    "÷" : .BinaryOperation({ $0 / $1 }),
    "+" : .BinaryOperation({ $0 + $1 }),
    "?" : .BinaryOperation({ $0 - $1 }),
    "=" : .Equals
]
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我删除以下内容:

"±" : .UnaryOperation({ -$0 })
"+" : .BinaryOperation({ $0 + $1 })
"?" : .BinaryOperation({ $0 - $1 })
Run Code Online (Sandbox Code Playgroud)

代码编译,否则会抛出错误.

另一个奇怪的事情是,如果我将其更改为:

"±" : .UnaryOperation({ (op1: Double) …
Run Code Online (Sandbox Code Playgroud)

xcode functional-programming compiler-errors ios swift

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

NextJS动态路由与模态重新加载导致叠加背景消失

我有一个非常简单的 NextJS 应用程序,打开一个页面将更新 URL,但不会触发导航,而是在模式中显示内容。URL 仍然反映实际页面位置,任何刷新都会将用户带到那里。

当模态打开时,我仍然希望将原始内容保留在背景中褪色的页面之外,并且模态应该出现在前面。

现在,当我的模态打开时,原始背景内容会消失而不是在背景中褪色。

我已经在代码沙箱中复制了这个问题: https://codesandbox.io/s/replicating-backdrop-disappearing-rqt21?file=/pages/index.js

在代码沙盒示例中,当您单击登录按钮时,您将看到模式有效,但原始背景消失了。我怎样才能让背景内容褪色。

请帮忙。

javascript reactjs next.js

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

无法访问localhost:80上的容器的Web服务器

我无法访问容器的Web服务器,localhost:80但我可以访问Web服务器127.0.0.1:80.

我究竟做错了什么?

我在Mac上安装了docker Version 1.12.2-rc1-beta27(build:12496).

我用命令运行了一个容器docker run -d -p 80:80 training/webapp python app.py.

容器具有以下属性

$docker ps -l
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
baaf4676e548        training/webapp     "python app.py"     22 minutes ago      Up 22 minutes       0.0.0.0:80->5000/tcp   big_volhard
Run Code Online (Sandbox Code Playgroud)

我的理解是我应该可以访问该网站localhost:80.

这不起作用.我收到错误消息

Could not get any response
Run Code Online (Sandbox Code Playgroud)

我知道我使用Docker for Mac,因为我已经运行了命令env | grep DOCKER并且它没有返回任何输出.

第一次更新:我/etc/hosts看起来像:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
Run Code Online (Sandbox Code Playgroud)

第二次更新:我也注意到当我使用命令运行容器时docker run -d -P training/webapp python app.py,然后localhost:autoGeneratedPortNumber工作. …

docker docker-machine

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

如何删除反应导航顶部栏中选项卡之间的空白

如何删除反应导航顶部栏中选项卡之间的空白。所以应该发生的是选项卡大小应该根据屏幕大小进行调整。

这就是我的导航目​​前的样子。

在此输入图像描述

您可以看到选项卡非常大。它们占用了太多空间。我怎样才能获得这些空白,以便选项卡只占用足够的大小来适合选项卡名称。

我尝试过造型Tab.Navigator但没有成功。例如,我尝试过以下操作:

<Tab.Navigator
      initialRouteName="All"
      tabBarOptions={{
        scrollEnabled: true,
        labelStyle: { padding: 0, margin: 0, border: 0 },
        tabStyle: { padding: 0, margin: 0, border: 0 },
      }}
      lazy={true}
      style={{ padding: 0, margin: 0, border: 0 }}
    >

Run Code Online (Sandbox Code Playgroud)
import React from "react";
import { createStackNavigator } from "@react-navigation/stack";
import { createMaterialTopTabNavigator } from "@react-navigation/material-top-tabs";

import Home from "../screens/Home";

const Tab = createMaterialTopTabNavigator();
const Stack = createStackNavigator();

const HomeTabNavigation = () => {
  return (
    <Tab.Navigator
      initialRouteName="All"
      tabBarOptions={{
        scrollEnabled: …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native react-native-navigation react-native-tabnavigator

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

console.log()语句中的布尔条件

我刚刚注意到你可以在console.log中放置布尔表达式,例如console.log("hey" || 2)在这种情况下hey将打印到控制台窗口.

我并不是100%确定console.log在其中存在条件时如何确定要打印的内容.

javascript console.log

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

Swift - 如何在点击按钮时测试标签是否已更新

我去了一个非常简单的计算器,我试图测试一个标签是否在点击按钮时更新.

我的测试方法如下所示:

let app = XCUIApplication()
app.buttons["9"].tap()
Run Code Online (Sandbox Code Playgroud)

我可以直观地看到标签正在更新,但我不确定如何测试它.

我想我需要使用XCUIElementQueryAPI来查询标签,然后断言标签文本已经改变.我只是不确定该怎么做.

我不确定以下问题:

  • 我是否需要知道标签能够查询的值是什么?
  • 是否有一种方法可以在不知道应用程序启动时的值是什么时查询标签?

ui-testing ios swift xcode7 xcode-ui-testing

4
推荐指数
2
解决办法
3565
查看次数

构建Dockerfile时linux源命令不起作用

我有一个定义Ruby on Rails堆栈的Dockerfile.

这是Dockerfile:

FROM ubuntu:14.04
MAINTAINER example <examplen@example.com>

# Update
RUN apt-get update

# Install Ruby and Rails dependencies
RUN apt-get install -y \
ruby \
ruby-dev \
build-essential \
libxml2-dev \
libxslt1-dev \
zlib1g-dev \
libsqlite3-dev \
nodejs \
curl

RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

RUN curl -sSL https://get.rvm.io | bash -s stable --rails

RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm"

# Install Rails
RUN gem install rails

# Create a new Rails app under /src/my-app
RUN mkdir -p …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile

4
推荐指数
2
解决办法
7894
查看次数

“npx create-react-app appname”不起作用

当我运行时,npx create-react-app appname我收到以下错误消息:

You are running `create-react-app` 4.0.0, which is behind the latest release (4.0.1).

We no longer support global installation of Create React App.

Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app

The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/

npm ERR! code 1
npm ERR! path /Users/hat/Projects/youtube/react
npm ERR! command failed
npm ERR! command sh -c create-react-app loll …
Run Code Online (Sandbox Code Playgroud)

node.js npm reactjs create-react-app npx

3
推荐指数
2
解决办法
2313
查看次数

将域从一个 AWS 账户转移到另一个 AWS 账户

我正在尝试使用 AWS CLI 将域名从一个 AWS 账户转移到另一个 AWS 账户。当我尝试转移域时,出现以下错误:

Connect timeout on endpoint URL: "https://route53domains.eu-west-1.amazonaws.com/"

我正在使用以下命令转移域

aws route53domains transfer-domain-to-another-aws-account --domain-name <value> --account-id <value> --profile personal

我检查了 aws 配置文件,看起来不错。它看起来像这样:

[profile personal]
aws_access_key_id = somekey
aws_secret_access_key = somesecretkey
region = us-west-2
Run Code Online (Sandbox Code Playgroud)

我还确保用户具有正确的权限。用户拥有以下权限

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "route53domains:*",
            "Resource": "*"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

并且还有AdministratorAccessAWS 托管策略。

确保我可以与 AWS 通信。我运行了一个简单的命令aws s3 ls --profile personal,它工作正常。AWS 以 S3 的内容作为回应。

我安装的 AWS CLI 版本是 aws-cli/2.0.18 Python/3.7.4 Darwin/19.4.0 botocore/2.0.0dev22 …

amazon-s3 amazon-web-services amazon-route53 aws-cli

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

TableView - 编辑聚焦单元格

我有一个侦听键盘事件的事件监听器.当我尝试使用键事件进入编辑模式时,由于某些奇怪的原因,不正确的单元格进入编辑模式.

例如,我想编辑一个单元格.我使用键盘箭头转到我想要编辑的单元格,即聚焦的单元格.通过单击键盘上的字母,焦点单元格应进入编辑模式.当我尝试编辑聚焦单元格时,错误的单元格进入编辑模式.

private final class EditCell extends TableCell<SimpleStringProperty, String> implements GenericTable
{

    public EditCell()
    {
        // Add event listsner. table is a TableView
        table.setOnKeyPressed(keyEvent -> this.handleKeyPressed(keyEvent));
    }

    public void handleKeyPressed(KeyEvent key)
    {
        // Keyboard events
        if (key.getCode().isLetterKey())
        {
            if (!this.isEditing())
            {

                this.edit = true;

                // focus index
                int focusIndex = this.table.getSelectionModel().getFocusedIndex();

                this.changeTableCellFocus(this.table, focusIndex);

                this.startEdit();
            }
        }
    }


    // startEdit() function
    @Override
    public void startEdit()
    {
        if (this.edit)
        {
            LOGGER.info("Start editing on cell index: " + this.getIndex());
            super.startEdit();
            this.createTextField();
            this.setText(null);
            this.setGraphic(this.textField); …
Run Code Online (Sandbox Code Playgroud)

java javafx focus tableviewcell

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

如何在Swift中检查字符串是否为有效的双精度

举例来说,您有:

var possibleDouble = Double("0.") 
Run Code Online (Sandbox Code Playgroud)

possibleDouble评估为Optional(0.0)。

就我而言,这"0."是无效的Double,possibleDouble应该是有效的nil。有没有一种聪明的方法来检查"0."或这种形式的东西不是有效的Double。

编辑:有效的电话号码(无论它是一个Int,Double,Float或Decimal)可以是只能在格式NN或N,其中N一些数量。期间前后可以有一个或多个数字。

string double swift

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