我总是了解到使用单元测试进行最大程度的代码覆盖是很好的.我还听到像微软这样的大公司的开发人员说他们编写了比可执行代码本身更多的测试代码.
现在,这真的很棒吗?它有时似乎完全没有时间损失,只会使维护更加困难吗?
例如,假设我有一个方法DisplayBooks()可以填充数据库中的书籍列表.产品要求表明,如果商店中有超过一百本书,则只能显示一百本.
所以,有了TDD,
BooksLimit(),这将在数据库中保存两百本书,调用DisplayBooks()并执行Assert.AreEqual(100, DisplayedBooks.Count).DisplayBooks()通过将结果限制设置为100来改变那么,直接进入第三步是不是更容易,而且根本不进行BooksLimit()单元测试?当需求从100个书籍限制改为200个限制,更改只有一个字符而不是更改测试,运行测试以检查它是否失败,更改代码并再次运行测试以检查是否成功时,是不是更敏捷?
注意:我们假设代码已完整记录.否则,有些人可能会说,他们是对的,进行完整的单元测试将有助于理解缺乏文档的代码.实际上,进行BooksLimit()单元测试将非常清楚地显示存在最大数量的书籍,并且该最大数量为100.进入非单元测试代码将更加困难,因为这样的限制可能是虽然for (int bookIndex = 0; bookIndex < 100; ...或实施foreach ... if (count >= 100) break;.
我正在尝试编写一些引用bool.xml文件的代码,并引用bool中的当前值.
<bool name="enableQAurl">true</bool>
Run Code Online (Sandbox Code Playgroud)
有了这个我希望能够在代码中引用它,所以如果它设置为True它会做一些事情,如果是false则做其他事情.只是一个简单的If和else语句.
任何代码参考或反馈都非常感谢.
我想要与所有本地用户及其相关群组(用户,超级用户,管理员等)进行报告.
我以这种方式得到用户:
$adsi = [ADSI]"WinNT://."
$adsi.psbase.children | where {$_.psbase.schemaClassName -match "user"} | select @{n="Name";e={$_.name}}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何检索他们的团体.提前致谢.
我拥有:带有Textviews和复选框的自定义列表视图.
public class NewQAAdapterSelectFriends extends BaseAdapter {
private LayoutInflater mInflater;
private Person[] data;
public NewQAAdapterSelectFriends(Context context) {
mInflater = LayoutInflater.from(context);
}
public void setData(Person[] data) {
this.data = data;
}
@Override
public int getCount() {
return data.length;
}
@Override
public Object getItem(int item) {
return data[item];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = …Run Code Online (Sandbox Code Playgroud) 我提出了我的教授在课堂上展示的问题,我的O(n*log(n))解决方案:
给出一个n我们想要执行以下n-1时间的数字列表:
x,y从列表中提取两个最小元素并显示它们z,在哪里z = x+y z回列表为O(n*log(n))和建议数据结构和算法O(n)
解:
我们将使用最小堆:
仅创建一次堆就需要O(n).之后,提取两个最小元素将采用O(log(n)).放置z到堆中将采取为O(log(n))的.
执行上述n-1时间需要O(n*log(n)),因为:
O(n)+O(n?(logn+logn ))=O(n)+O(n?logn )=O(n?logn )
Run Code Online (Sandbox Code Playgroud)
但我怎么能在O(n)中做到这一点?
编辑:
通过说:" x,y从列表中提取两个最小元素并呈现它们 ",我的意思是printf("%d,%d" , x,y),当前列表中的最小元素x和y位置.
我有一个代码,我想根据正斜杠"/"拆分.
每当我有一个基于"////"的正则表达式分割时,它永远不会分裂并给我整个字符串.我尝试用文件分隔符替换,它给出了"\",然后用"\\"分割,但不是下面的代码.
下面是测试的代码
package org.saurav.simpletests.string;
import java.io.File;
public class StringManipulator {
public static void main(String a[]){
String testString ="/UserId/XCode/deep";
//testString = testString.replace("/", File.separator);
//testString = testString.replace("/", "_");
testSplitStrings(testString);
}
/**
* Test the split string
* @param path
*/
public static void testSplitStrings(String path){
System.out.println("splitting of sprint starts \n");
String[] paths = path.split("////");
for (int i = 0; i < paths.length; i++) {
System.out.println("paths::"+i+" "+paths[i]+"\n");
}
System.out.println("splitting of sprint ends");
}
}
Run Code Online (Sandbox Code Playgroud)
欢呼,索拉夫
我的问题是如何在Google Developers Console中正确设置软件包名称和SHA-1证书指纹,以限制我的Android API密钥在我的应用中的使用.
如果我在"限制Android应用的使用限制"部分中没有设置任何内容,我对Google Translate API的请求就能正常运行.API通常使用状态代码200和我的预期结果进行响应.
但是,当我使用Developers Console为我的应用程序指定包名称和SHA-1证书指纹时,我始终获得403 Forbidden响应,如下所示:
HTTP/1.1 403 Forbidden
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
Date: Sun, 29 Nov 2015 21:01:39 GMT
Expires: Sun, 29 Nov 2015 21:01:39 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic,p=1
Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"
Content-Length: 729
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request …Run Code Online (Sandbox Code Playgroud) 我有一个断点操作,并使用下拉列表中的日志选项.我想打印出字符串(摘要)值.我这样做:
the person name is: @p.name@
Run Code Online (Sandbox Code Playgroud)
但是会打印内存地址.我可以切换到Debugger Command选项并执行
po f.name
Run Code Online (Sandbox Code Playgroud)
但后来我丢失了我的描述,如第一个选项中所使用的那样.使用Log选项,有没有办法打印字符串值而不是内存地址?
我想在android studio中添加我的Android应用程序中的admob.我几乎在那里,但我得到的错误:
Namespace 'ads' not bound
Run Code Online (Sandbox Code Playgroud)
这也是我的广告xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
<TextView
android:id="@+id/beerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:textStyle = "bold"
android:padding="5dip"
>
</TextView>
<ImageView android:id="@+id/image"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_margin="10dip"/>
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:shrinkColumns="*"
android:stretchColumns="*">
<TableRow
android:id="@+id/tableStatTitles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="@+id/abvTitle"
android:text="ABV"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView
android:id="@+id/IBUTitle"
android:text="IBU"
android:gravity="center"
android:textStyle = "bold"
android:textSize="20sp"
android:layout_weight="1"
></TextView>
<TextView …Run Code Online (Sandbox Code Playgroud)