我必须在类中测试一个方法,该方法使用Scanner类进行输入.
package com.math.calculator;
import java.util.Scanner;
public class InputOutput {
public String getInput() {
Scanner sc = new Scanner(System.in);
return sc.nextLine();
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用JUnit测试它,但不知道如何做到这一点.
我尝试使用以下代码,但它不会工作.
package com.math.calculator;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class InputOutputTest {
@Test
public void shouldTakeUserInput() {
InputOutput inputOutput= new InputOutput();
assertEquals("add 5", inputOutput.getInput());
}
}
Run Code Online (Sandbox Code Playgroud)
我也想和Mockito一起尝试(使用模拟......当...然后返回)但不知道该怎么做.
我有一个镶木地板,按以下方式分区:
data
/batch_date=2020-01-20
/batch_date=2020-01-21
/batch_date=2020-01-22
/batch_date=2020-01-23
/batch_date=2020-01-24
Run Code Online (Sandbox Code Playgroud)
这里batch_date是分区列,是日期类型。
我只想读取最新日期分区中的数据,但作为消费者,我不知道最新值是什么。
我可以通过类似的方式使用一个简单的组
df.groupby().agg(max(col('batch_date'))).first()
Run Code Online (Sandbox Code Playgroud)
虽然这可行,但这是一种非常低效的方法,因为它涉及到 groupby。
我想知道我们是否可以以更有效的方式查询最新的分区。
谢谢。
我希望Marshal和Unmarshal是递归类型,如下所示:
type Dog struct {
age int
sibling *Dog
}
Run Code Online (Sandbox Code Playgroud)
在golang有什么办法吗?我试过json.Marshal,但它不起作用.
我使用scanf获取多个整数输入并将其保存在数组中
while(scanf("%d",&array[i++])==1);
Run Code Online (Sandbox Code Playgroud)
例如,输入整数由空格分隔
12 345 132 123
Run Code Online (Sandbox Code Playgroud)
我在另一篇文章中读过这个解决方案
但问题是while循环没有终止.
该声明的问题是什么?
在以下代码中
#include <stdio.h>
int main()
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到输出为"False"而不是"True".我的理解是sizeof运算符只返回int的大小,在这种情况下为4.
为什么评估条件为假?
我试图从C#项目调用本机C++代码.为此,我按照这篇文章中的步骤进行操作.
但是当我在C++文件中创建一个巨大的数组时,我得到了一个stackoverflow异常.这是代码:
//CSharpTest.h
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpTest
{
class Program
{
static void Main(string[] args)
{
CpTest.Class1 instance = new CpTest.Class1();
Console.WriteLine(instance.DoSomething());
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
和c ++文件
// CpTest.h
#pragma once
using namespace System;
namespace CpTest {
public ref class Class1
{
public:
int DoSomething(){
int arr[640 * 480];
return 123;
}
// TODO: Add your methods for this class here.
};
}
Run Code Online (Sandbox Code Playgroud)
数组声明导致stackoverflow异常.
早些时候,当我只运行本机C++代码时,我通过增加项目属性中的"堆栈保留大小"来增加堆栈大小.
但对于这种情况,我不知道该怎么做.