我在 Angular 的一项服务中有一个只读属性:
@Injectable({
providedIn: 'root'
})
export class MyService {
private readonly timeIntervals: any;
}
constructor(private readonly config: AppConfig) {
this.timeIntervals = this.config.getResourceByKey(this.timeIntervalString);
}
getTimeIntervalMenuItem(): Array<IElementData>{
const menuListItems = new Array<IElementData>();
let index = 0;
for (const item of Object.keys(this.timeIntervals)) {
menuListItems.push({
id: this.menuItem + index.toString(),
label: this.timeIntervals[item].toString()
});
index++;
}
return menuListItems;
}
export interface IElementData {
label?: string;
value?: string;
id?: string;
active?: string;
}
Run Code Online (Sandbox Code Playgroud)
在为同一服务编写测试时,如何为 timeIntervals 分配值?
我所做的是:
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
MyService,
] …Run Code Online (Sandbox Code Playgroud) 我在C#中浏览了Arraylist的属性.我做的是:
ArrayList listInt = new ArrayList();
listInt.Add(9);
listInt.Add(10);
listInt.Add(11);
Console.WriteLine($"Capacity Before: {listInt.Capacity}");
Run Code Online (Sandbox Code Playgroud)
输出为4,很好.接下来我尝试了AddRange()属性:
ArrayList list2 = new ArrayList();
list2.Add("SAM");
list2.Add("MAN");
list2.Add("TAN");
listInt.AddRange(list2);
Console.WriteLine($"Capacity After: {listInt.Capacity}");
Run Code Online (Sandbox Code Playgroud)
输出为8.
产量
我的ArrayList的容量如何变为8?