小编Sha*_*ane的帖子

每次测试都会重置Mock对象吗?

我正在使用Mockito框架在我的JUnit测试中创建Mock对象.每个模拟器都知道调用了哪些方法,所以在我的测试中我可以编写

verify(myMock, atLeastOnce()).myMethod();
Run Code Online (Sandbox Code Playgroud)

我想知道这个内部的模拟知识是否会在我的测试中持续存在?如果它确实存在,那么当我verify在两个测试中使用相同的方法时,我可能会得到误报.

一个代码示例

@RunWith(MockitoJUnitRunner.class)
public class EmrActivitiesImplTest {

    @Mock private MyClass myMock;

    @Before
    public void setup() {
        when(myMock.myMethod()).thenReturn("hello");
    }

    @Test
    public void test1() {
        // ..some logic
        verify(myMock, atLeastOnce()).myMethod();
    }

    @Test
    public void test2() {
        // ..some other logic
        verify(myMock, atLeastOnce()).myMethod();
    }  
}
Run Code Online (Sandbox Code Playgroud)

模拟状态是持久的 - test2将通过,因为test1的验证方法已通过

模拟状态被重置 - 如果未调用myMock.myMethod(),test2将失败

java junit mockito

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

字符串格式JSON字符串给出KeyError

为什么这段代码会给出一个KeyError

output_format = """
{ 
    "File": "{filename}", 
    "Success": {success}, 
    "ErrorMessage": "{error_msg}", 
    "LogIdentifier": "{log_identifier}" 
}
"""

print output_format.format(filename='My_file_name',
                           success=True,
                           error_msg='',
                           log_identifier='123')
Run Code Online (Sandbox Code Playgroud)

错误信息:

KeyError: ' "File"'
Run Code Online (Sandbox Code Playgroud)

python string format json

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

在haskell的双重地图?

我仍然是一名哈斯克尔初学者.我可以在哈斯克尔做双重地图吗?

例如,如果我有一个[[Char]]并且我想将每个Char中的每个转换[Char]为小写,那么有一种简单的方法可以做到这一点,而不是像:

exampleF [] = []
exampleF (x:xs) = (map toLower x) : exampleF xs
Run Code Online (Sandbox Code Playgroud)

mapping haskell

16
推荐指数
2
解决办法
5993
查看次数

使用SSE获取__m128i向量中的最大值?

我刚刚开始使用SSE,我很困惑如何获得a的最大整数值(max)__m128i.例如:

__m128i t = _mm_setr_ps(0,1,2,3);
// max(t) = 3;
Run Code Online (Sandbox Code Playgroud)

搜索引导我去MAXPS指导,但我似乎无法找到如何使用它"xmmintrin.h".

此外,是否有任何"xmmintrin.h"您建议的文档,而不是查看头文件本身?

c x86 assembly sse

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

通过简单地使用指向它中间的指针来拆分C数组是不好的做法吗?

我在c中实现了一个合并排序版本.对于第一步,我必须将数组拆分为子数组.

通过使用两个指针来简单地执行此操作是不好的做法,一个指向原始数组的开头而第二个指向中间?

或者我应该malloc 2个新的内存插槽,在这里复制适当的值,然后保持指向这个空间的指针?

c arrays malloc pointers

8
推荐指数
2
解决办法
783
查看次数

使用'/'加长双?

我试图理解为什么在以下方式中使用带有long double的'/'会导致0.000000值,而使用double的相同代码则不会

double d = (double)total_results / (double)total_points;
Run Code Online (Sandbox Code Playgroud)

给出值0.785403但是

long double d = (long double)total_results / (long double)total_points;
Run Code Online (Sandbox Code Playgroud)

给出值0.000000.我想为'total_results/total_points'获取最准确的值

编辑:最后错误只是我使用'%f'而不是'%Lf'输出它

之前

printf("Running on %d thread(s), results is %f.\n", NUM_THREADS, d);    
Run Code Online (Sandbox Code Playgroud)

printf("Running on %d thread(s), results is %Lf.\n", NUM_THREADS, d); 
Run Code Online (Sandbox Code Playgroud)

c precision double

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

如何在这个实例中应用使用地图?

我有一个月份和字符串列表.我想检查字符串中是否有任何月份.我还有一个函数,可以搜索字符串中的单词.我是否必须重写该功能,还是可以使用某种形式的地图?

fullMons = ["january", "febuary", "march", "april", "may", "june", "july", "september", "october", "november", "december"]

searchStrList :: String -> [String] -> Bool
searchStrList str strList = elem (map toLower str) $ convertToLower $ words strList
Run Code Online (Sandbox Code Playgroud)

我如何利用这些函数来做这样的事情:

check :: String -> Bool 
check str = searchStrList "january" || searchStrList "febuary" || ...
Run Code Online (Sandbox Code Playgroud)

仍然只是学习Haskell,所以对我的代码的任何其他评论表示赞赏.谢谢

haskell

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

在所有活动按钮上轻松设置setOnClickListener()

Android开发新手,但不是Java新手.现在我在onCreate()方法中的代码是非常基本的:

    Button b1 = (Button) findViewById(R.id.button1);
    Button b2 = (Button) findViewById(R.id.button2);
    Button b3 = (Button) findViewById(R.id.button3);
    Button b4 = (Button) findViewById(R.id.button4);
    Button b5 = (Button) findViewById(R.id.button5);
    Button b6 = (Button) findViewById(R.id.button6);
    Button b7 = (Button) findViewById(R.id.button7);
    Button b8 = (Button) findViewById(R.id.button8);
    Button b9 = (Button) findViewById(R.id.button9);
    Button b10 = (Button) findViewById(R.id.button10);
    Button b11 = (Button) findViewById(R.id.button11);
    Button b12 = (Button) findViewById(R.id.button12);
    Button b13 = (Button) findViewById(R.id.button13);
    Button b14 = (Button) findViewById(R.id.button14);
    Button b15 = (Button) findViewById(R.id.button15);
    Button sqrt = (Button) …
Run Code Online (Sandbox Code Playgroud)

java android

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

将"R.id.myID"从String转换为int值R.id.myID?

我的观点上的文字代表一个id.因此,当点击时,我想获得对该资源的引用.以下错误代码代表我正在尝试做的事情

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.categories);

    Bundle bundle = getIntent().getExtras();
    int myArrayID = bundle.getInt("category_id", 0); 
    String [] myArray = getResources().getStringArray(myArrayID);

    setListAdapter(new CategoryAdapter(this, android.R.layout.simple_list_item_1, R.id.categoryText, myArray)); 
    ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
            String myIdString = (String) ((TextView) view.findViewById(R.id.categoryText)).getText();
            int myIdInt = // convert to the correct id that is represented by this string myIdString
            Intent intent = new Intent(Categories.this, Categories.class);
            intent.putExtra("category_id", myIdInt);
            startActivity(intent);
        }
      });
}
Run Code Online (Sandbox Code Playgroud)

我明白为什么这种方法不起作用.例如,视图将具有文本"example1",然后将需要获取引用的R.id.example1值.显然我正在接近这个错误的方式,并希望得到一些指导. …

java android

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

这可能在Oracle/Sql中吗?

我有两张桌子:

CREATE TABLE Event_details( event_no INTEGER AUTOINCREMENT NOT NULL,
no_players INTEGER NOT NULL,
game_type VARCHAR(20) NOT NULL,
payout_positions INTEGER NOT NULL, 
PRIMARY KEY(event_no)
CONSTRAINT check_game_type CHECK(game_type IN ('NLH','NLO','PLO','PLH','STUD','HORSE')
CONSTRAINT check_no_players CHECK (no_players > 1)
CONSTRAINT check_payouts CHECK (payout_positions > 0 AND payout_positions < no_players));

CREATE TABLE Venue( venue_no INTEGER AUTOINCREMENT NOT NULL,
name VARCHAR(20) NOT NULL,
location VARCHAR(20) NOT NULL,
capacity INTEGER NOT NULL,
PRIMARY KEY (venue_no)
CONSTRAINT check_capacity CHECK (capacity > 0));
Run Code Online (Sandbox Code Playgroud)

和他们之间的外键:

ALTER TABLE Event_details
ADD FOREIGN KEY …
Run Code Online (Sandbox Code Playgroud)

sql oracle triggers constraints

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

标签 统计

c ×3

java ×3

android ×2

haskell ×2

arrays ×1

assembly ×1

constraints ×1

double ×1

format ×1

json ×1

junit ×1

malloc ×1

mapping ×1

mockito ×1

oracle ×1

pointers ×1

precision ×1

python ×1

sql ×1

sse ×1

string ×1

triggers ×1

x86 ×1