本文整理汇总了C#中SortedList.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Clear方法的具体用法?C# SortedList.Clear怎么用?C# SortedList.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClearBasic
public void TestClearBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
String s1 = null;
String s2 = null;
int i = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// now Clear the list and verify the Count
sl2.Clear(); //removes 0 element
Assert.Equal(0, sl2.Count);
// Testcase: add few key-val pairs
for (i = 0; i < 100; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
// now get the list Count and verify
Assert.Equal(100, sl2.Count);
// now Clear the list and verify the Count
sl2.Clear(); //removes all the 100 elements
Assert.Equal(0, sl2.Count);
}
示例2: GetShowItems
/// <summary>
/// 获得显示项的已排序的列表
/// </summary>
/// <param name="strRTypeID"></param>
/// <param name="intSummaryOrDetail"></param>
/// <param name="intUporDown"></param>
/// <returns></returns>
public static SortedList<int, string> GetShowItems(string strRTypeID, int intSummaryOrDetail, int intUporDown)
{
SortedList<int, string> showItems = new SortedList<int, string>();
string strSql = "select * from T_ReceiptModCfg where RTypeID='{0}' and SummaryOrDetail={1} and UporDown={2}";
strSql = string.Format(strSql, strRTypeID, intSummaryOrDetail, intUporDown);
DataTable dt = (new SqlDBConnect()).Get_Dt(strSql);
if (dt == null || dt.Rows.Count <= 0)
return null;
showItems.Clear();
foreach (DataRow dr in dt.Rows)
{
showItems.Add(Convert.ToInt32(dr["OrderNum"].ToString().Trim()), dr["ShowItem"].ToString().Trim());
}
return showItems;
}
示例3: createPedestrians
public void createPedestrians()
{
positions = positions.OrderBy(x => x.getID()).ThenBy(y => y.getTime()).ToList<PedestrianPosition>();
SortedList currentList = new SortedList ();
population = new int[(int)pc.total_time + 1];
for (int i = 0; i < positions.Count; i ++) {
if (positions.Count() > (i + 1) && positions[i].getX() == positions[i + 1].getX() && positions[i].getY() == positions[i + 1].getY()) {
// Only take into account time steps with changed coordinates. We want smooth animation.
continue;
}
currentList.Add(positions[i].getTime(), positions[i]);
population[(int) positions[i].getTime ()]++;
if ((i == (positions.Count - 1) || positions[i].getID()!=positions[i + 1].getID()) && currentList.Count > 0) {
//GameObject p = (GameObject) Instantiate(ped);
GameObject p = null;
//diff pedestrian prefabs
int gender = rnd.Next(0, 2); //Debug.Log(gender);
if(gender == 0)
p = (GameObject) Instantiate(ped1);
else
p = (GameObject) Instantiate(ped2);
p.tag = "pedestrian";
if(p == null)
throw new UnityException("not initialized pedestrian");
p.GetComponent<Pedestrian>().setGender(gender);
//p.transform.parent = null;
p.GetComponent<Pedestrian>().setPositions(currentList);
p.GetComponent<Pedestrian>().setID(positions[i].getID());
pedestrians.Add(p);
currentList.Clear();
p.transform.SetParent(Pedestrians.transform);
}
}
}
示例4: checkForNewPackages
private void checkForNewPackages() {
var newUpdates = new SortedList<releaseInfo, updatePackage>();
//Alle Pakete vorher schon sortieren, um den "SP-Bug" zu beheben.
var allUpdates = new SortedList<releaseInfo, updatePackage>();
foreach (updatePackage uPackage in currentConfiguration.updatePackages)
allUpdates.Add(uPackage.releaseInfo, uPackage);
foreach (var package in allUpdates) {
//Überspringe Update wenn noch nicht veröffentlicht
if (!package.Value.Published)
continue;
//Überprüfe ob die Zielarchitektur stimmt
if (package.Value.TargetArchitecture != updatePackage.SupportedArchitectures.Both &&
package.Value.TargetArchitecture != Helper.GetArchitecture())
continue;
if (package.Value.releaseInfo > _controllerInstance.releaseInfo) {
//Überspringe das Update wenn der Releasetyp nicht zum eingestellten Filter passt.
if (!_controllerInstance.releaseFilter.Contains(package.Value.releaseInfo.Type))
continue;
//Anfrage an das Programm schicken, ob das Update bestätigt werden soll.
if (!_controllerInstance.onConfirmUpdatePackage(new confirmUpdatePackageEventArgs(package.Value)))
continue;
//Wenn dieses Updatepaket nur für bestimmte Versionen verfügbar sein soll
if (package.Value.UseOwnVersionList) {
bool versionFound = false;
foreach (VersionEx version in package.Value.OwnVersionList)
if (version.ToVersion().Equals(new Version(_controllerInstance.releaseInfo.Version))) {
versionFound = true;
break;
}
if (!versionFound)
continue;
}
//Wenn das aktuelle Update ein ServicePack ist, dann alle vorherigen entfernen
if (package.Value.isServicePack)
newUpdates.Clear();
newUpdates.Add(package.Value.releaseInfo, package.Value);
}
}
foundUpdates.Clear();
foreach (var item in newUpdates) {
foundUpdates.Add(item.Value);
}
}
示例5: BestGainMvNumeric
/// <summary>
/// Receives one PredMvIdx to be tested, and the constant and returns:
///
/// Return[0] the best value for the coefficient
/// Return[1] the lowestSplitImp for this coefficient
/// </summary>
/// <param name="n"></param>
/// <param name="bestCoefLst"></param>
/// <param name="c"></param>
/// <param name="testPredMvIdx"></param>
/// <returns></returns>
public static double[] BestGainMvNumeric(NodeTargetCategorical n, double c, int testPredMvIdx, List<int> optimisedVariableLst, FrmGraph fg)
{
double OptVarSum;
bool infoNotYetCalculated = true;
double leftImp = 0, rightImp = 0;
double v, az, aSplit, xts,aSplitB=-9999999999;
SortedList<double, int> azLst = new SortedList<double, int>();
double leftCount = 0, rightCount = 0;// Left and right item count
SortedList<string, int> leftNode = new SortedList<string, int>();
SortedList<string, int> rightNode = new SortedList<string, int>();
double lowestSplitImp = 9999999, splitImp = 9999999;
if (!Def.ExperimentRunning) {
fg.ALst.Clear();
fg.AbsLst.Clear();
}
azLst.Clear();
for (int y = 0; y < n.Table.RowCount; ++y) {
OptVarSum = 0;
//for (int i = 0; i < optimisedVariableLst.Count; ++i) {
// OptVarSum += n.PredMvLst[optimisedVariableLst[i]].Coef * n.PredMvLst[optimisedVariableLst[i]].X(y);
for (int i = 0; i < n.PredMvLst.Count; ++i) {
OptVarSum += n.PredMvLst[i].Coef * n.PredMvLst[i].X(y);
}
v = OptVarSum + c;
if (n.PredMvLst[testPredMvIdx].X(y) != 0) {
az = ((n.PredMvLst[testPredMvIdx].Coef * n.PredMvLst[testPredMvIdx].X(y)) - v) / n.PredMvLst[testPredMvIdx].X(y);
if (!azLst.ContainsKey(az) ) {
azLst.Add(az, 1);
if (!Def.ExperimentRunning)
fg.ALst.Add((float)az);
}
}
}
for (int azIdx = 0; azIdx < azLst.Count - 1; ++azIdx) {
//Finally we got a new linear coefficient for a variable that
//had linear coefficient = 0
//The new hyperplane is:
// A1X1 + (1)X2 + c = 0 (c= - bestSplitNorm)
// (new midpoint coef) * testVar + (coordinate of the bestSplit variable) - bestSplitNorm;
// aSplit * Fcn.NormP1(testLst[y], PredictorLst[i].LowerNumber, PredictorLst[i].HigherNumber);
aSplit = (azLst.Keys[azIdx] + azLst.Keys[azIdx + 1]) / 2;
leftNode.Clear();
rightNode.Clear();
leftCount = 0;
rightCount = 0;
if (!Def.ExperimentRunning)
fg.AbsLst.Add((float)aSplit);
for (int y = 0; y < n.Table.RowCount; ++y) {
xts = n.PredMvLst[testPredMvIdx].X(y);
OptVarSum = 0;
for (int i = 0; i < optimisedVariableLst.Count; ++i) {
OptVarSum += n.PredMvLst[optimisedVariableLst[i]].Coef * n.PredMvLst[optimisedVariableLst[i]].X(y);
}
if ((aSplit * xts + OptVarSum + c) <= 0) {
++leftCount;
if (!leftNode.ContainsKey(n.MvTb.Data.TC[y]))
leftNode.Add(n.MvTb.Data.TC[y], 1);
else
++leftNode[n.MvTb.Data.TC[y]];
} else {
++rightCount;
if (!rightNode.ContainsKey(n.MvTb.Data.TC[y]))
rightNode.Add(n.MvTb.Data.TC[y], 1);
else
++rightNode[n.MvTb.Data.TC[y]];
}
}
if (rightCount < Def.TreeMinNumberOfCasesPerNode || leftCount < Def.TreeMinNumberOfCasesPerNode)
continue;
leftImp = Gini.ImpCat(leftNode, (int)leftCount);
rightImp = Gini.ImpCat(rightNode, (int)rightCount);
if (infoNotYetCalculated) {
infoNotYetCalculated = false;
lowestSplitImp = (leftCount * leftImp + rightCount * rightImp) / n.Table.RowCount;
if (n.PredMvLst[testPredMvIdx].Variable.VariableTypeDetected == SchemaVariable.VariableTypeEnum.Categorical) {
MessageBox.Show("Error n.PredMvLst[testPredMvIdx].Variable is categorical ");
}
aSplitB = aSplit;
} else {
splitImp = (leftCount * leftImp + rightCount * rightImp) / n.Table.RowCount;
if (splitImp < lowestSplitImp) {
lowestSplitImp = splitImp;
if (n.PredMvLst[testPredMvIdx].Variable.VariableTypeDetected == SchemaVariable.VariableTypeEnum.Categorical) {
MessageBox.Show("Error n.PredMvLst[testPredMvIdx].Variable is categorical ");
}
aSplitB = aSplit;
//.........这里部分代码省略.........
示例6: DumpSchema
public void DumpSchema (XmlSchema schema)
{
schema.Compile (null);
SortedList sl = new SortedList ();
IndentLine ("**XmlSchema**");
IndentLine ("TargetNamespace: " + schema.TargetNamespace);
IndentLine ("AttributeGroups:");
foreach (DictionaryEntry entry in schema.AttributeGroups)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
DumpAttributeGroup ((XmlSchemaAttributeGroup) entry.Value);
sl.Clear ();
IndentLine ("Attributes:");
foreach (DictionaryEntry entry in schema.Attributes)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
DumpAttribute ((XmlSchemaAttribute) entry.Value);
sl.Clear ();
IndentLine ("Elements:");
foreach (DictionaryEntry entry in schema.Elements)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
DumpElement ((XmlSchemaElement) entry.Value);
sl.Clear ();
IndentLine ("Groups");
foreach (DictionaryEntry entry in schema.Groups)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
DumpGroup ((XmlSchemaGroup) entry.Value);
sl.Clear ();
IndentLine ("IsCompiled: " + schema.IsCompiled);
IndentLine ("Notations");
foreach (DictionaryEntry entry in schema.Notations)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
DumpNotation ((XmlSchemaNotation) entry.Value);
sl.Clear ();
IndentLine ("SchemaTypes:");
foreach (DictionaryEntry entry in schema.Notations)
sl.Add (entry.Key.ToString (), entry.Value);
foreach (DictionaryEntry entry in sl)
if (entry.Value is XmlSchemaSimpleType)
DumpSimpleType ((XmlSchemaSimpleType) entry.Value);
else
DumpComplexType ((XmlSchemaComplexType) entry.Value);
sl.Clear ();
}
示例7: TestIndexcAccessBasic
public void TestIndexcAccessBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
//
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
string s1 = null;
string s2 = null;
string s3 = null;
int i = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// Testcase: Set - null key, ArgExc expected
Assert.Throws<ArgumentNullException>(() =>
{
sl2[null] = "first value";
});
Assert.Equal(0, sl2.Count);
// Testcase: Set - null val, should pass
sl2["first key"] = (string)null;
Assert.Equal(1, sl2.Count);
// Testcase: vanila Set
sl2[(int)0] = "first value";
Assert.Equal(2, sl2.Count);
// Testcase: check to see whether the key is there
Assert.True(sl2.ContainsKey("first key"));
// Testcase: Get and check the value
sl2["first key"] = "first value";
s2 = (string)sl2["first key"];
Assert.Equal("first value", s2);
// Testcase: Set again with a diff value
sl2["first key"] = "second value";
Assert.Equal(2, sl2.Count);
// Testcase: now, Get again and check the value set
s2 = (string)sl2["first key"];
Assert.Equal("second value", s2);
sl2.Clear();
// Testcase: add 50 key-val pairs
for (i = 0; i < 50; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
//
// Testcase: now set their val again using Set (index, newVal)
//
for (i = 0; i < 50; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("new_val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2[s1] = s2;
}
Assert.Equal(50, sl2.Count);
// Testcase: check the values
for (i = 0; i < 50; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
//.........这里部分代码省略.........
示例8: ProcessUntrackedClusters
private List<Obstacle> ProcessUntrackedClusters(SceneEstimatorUntrackedClusterCollection clusters, List<Obstacle> trackedObstacles, Rect vehicleBox)
{
List<Obstacle> obstacles = new List<Obstacle>();
SortedList<Obstacle, List<Coordinates>> point_splits = new SortedList<Obstacle, List<Coordinates>>();
List<Coordinates> unclaimed_points = new List<Coordinates>(1500);
foreach (SceneEstimatorUntrackedCluster cluster in clusters.clusters) {
// clear out stored variables
point_splits.Clear();
unclaimed_points.Clear();
// now determine if the point belongs to an old obstacle
ObstacleClass targetClass;
if (cluster.clusterClass == SceneEstimatorClusterClass.SCENE_EST_HighObstacle)
targetClass = ObstacleClass.StaticLarge;
else
targetClass = ObstacleClass.StaticSmall;
// only add points that are not within a tracked obstacle's extruded polygon
for (int i = 0; i < cluster.points.Length; i++) {
Coordinates pt = cluster.points[i];
// iterate over all tracked cluster
bool did_hit = false;
if (useOccupancyGrid && Services.OccupancyGrid.GetOccupancy(pt) == OccupancyStatus.Free) {
occupancyDeletedCount++;
did_hit = true;
}
else if (vehicleBox.IsInside(pt)) {
did_hit = true;
}
else if (trackedObstacles != null) {
foreach (Obstacle trackedObs in trackedObstacles) {
if (trackedObs.extrudedPolygon != null && trackedObs.extrudedPolygon.BoundingCircle.IsInside(pt) && trackedObs.extrudedPolygon.IsInside(pt)) {
did_hit = true;
break;
}
}
}
// if there was a hit, skip this point
if (!did_hit) {
unclaimed_points.Add(pt);
}
//if (did_hit)
// continue;
//Obstacle oldObstacle = FindIntersectingCluster(pt, targetClass, previousObstacles);
//if (oldObstacle != null) {
// List<Coordinates> obstacle_points;
// if (!point_splits.TryGetValue(oldObstacle, out obstacle_points)) {
// obstacle_points = new List<Coordinates>(100);
// point_splits.Add(oldObstacle, obstacle_points);
// }
// obstacle_points.Add(pt);
//}
//else {
// unclaimed_points.Add(pt);
//}
}
// we've split up all the points appropriately
// now construct the obstacles
// we'll start with the obstacle belonging to an existing polygon
//foreach (KeyValuePair<Obstacle, List<Coordinates>> split in point_splits) {
// if (split.Value != null && split.Value.Count >= 3) {
// // the obstacle will inherit most of the properties of the old obstacle
// Obstacle obs = new Obstacle();
// obs.age = split.Key.age+1;
// obs.obstacleClass = split.Key.obstacleClass;
// // don't bother doing a split operation on these clusters -- they have already been split
// obs.obstaclePolygon = Polygon.GrahamScan(split.Value);
// obstacles.Add(obs);
// }
//}
// handle the unclaimed points
IList<Polygon> polygons = WrapAndSplit(unclaimed_points, split_area_threshold, split_length_threshold);
foreach (Polygon poly in polygons) {
// create a new obstacle
Obstacle obs = new Obstacle();
obs.age = 1;
obs.obstacleClass = targetClass;
obs.obstaclePolygon = poly;
obstacles.Add(obs);
}
}
// test all old obstacles and see if they intersect any new obstacles
// project the previous static obstacles to the current time frame
//.........这里部分代码省略.........
示例9: TestTrimToSizeBasic
public void TestTrimToSizeBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
//
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
String s1 = null;
String s2 = null;
String s3 = null;
int i = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
Assert.Null(s3);
// Testcase: add few key-val pairs
// start adding elements
for (i = 0; i < 32; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
//
// add one more elemnt now the capacity should be doubled
//
sl2.Add("key_32", "val_32");
Assert.Equal(33, sl2.Count);
//
// Testcase: now Remove few elements and TrimToSize
//
for (i = 0; i < 10; i++)
{
sl2.Remove("key_" + i.ToString()); // remove the current object
}
// Testcase: validate the Count and capacity
Assert.Equal(23, sl2.Count);
// now TrimToSize
sl2.TrimToSize();
// clear the list
sl2.Clear();
// now TrimToSize
sl2.TrimToSize();
}
示例10: OnBufferChanged
/// <summary>
/// Called when the contents of the text buffer change.
/// </summary>
/// <param name="sender">The object that raised the event.</param>
/// <param name="e">A <see cref="TextContentChangedEventArgs"/> that contains the event data.</param>
public override void OnBufferChanged(Object sender, TextContentChangedEventArgs e)
{
// Remove symbols from lines which were touched.
foreach (var change in e.Changes)
{
var oldLineStart = e.Before.GetLineFromPosition(change.OldPosition).LineNumber;
var oldLineEnd = e.Before.GetLineFromPosition(change.OldEnd).LineNumber;
for (int i = oldLineStart; i <= oldLineEnd; i++)
{
var line = e.Before.GetLineFromLineNumber(i);
var lineText = DiscardSingleLineComments(line.GetText());
RemoveSymbolsOnLine(e.Before, line.Extent.Span, lineText);
}
}
// Translate all of our symbols forward in time.
foreach (var symbol in symbols)
{
symbol.Value.TranslateTo(e.After);
symbolsTemp.Add(symbol.Value.Position, symbol.Value);
}
var temp = symbols;
symbols = symbolsTemp;
symbolsTemp = temp;
symbolsTemp.Clear();
// Add symbols from lines which were touched.
foreach (var change in e.Changes)
{
var newLineStart = e.After.GetLineFromPosition(change.NewPosition).LineNumber;
var newLineEnd = e.After.GetLineFromPosition(change.NewEnd).LineNumber;
for (int i = newLineStart; i <= newLineEnd; i++)
{
var line = e.After.GetLineFromLineNumber(i);
var lineText = DiscardSingleLineComments(line.GetText());
AddSymbolsOnLine(e.After, line.Extent.Span, lineText);
}
}
UpdateNesting();
}
示例11: runTest
//.........这里部分代码省略.........
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_34fj! - must not 've thrown ArgExc" );
Console.Error.WriteLine( sblMsg.ToString() );
}
++iCountTestcases;
if (sl2.Count != 1)
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_60ff! - Count == " );
sblMsg.Append( sl2.Count );
Console.Error.WriteLine( sblMsg.ToString() );
}
strLoc="Loc_120aa";
++iCountTestcases;
try
{
sl2[(Object)100] = 1;
}
catch (Exception exc)
{
++iCountErrors;
Console.Error.WriteLine ( "POINTTOBREAK: Error Err_49ff! - " + exc.ToString());
}
if (sl2.Count != 1)
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_2i20bc! - Count == " );
sblMsg.Append( sl2.Count );
Console.Error.WriteLine( sblMsg.ToString() );
}
sl2.Clear();
if (sl2.Count != 0)
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_03rf! - Count == " );
sblMsg.Append( sl2.Count );
Console.Error.WriteLine( sblMsg.ToString() );
}
strLoc="Loc_141aa";
for (i=0; i<100; i++)
{
++iCountTestcases;
sl2.Add (i+100, i);
}
if (sl2.Count != 100)
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_dhc3! - Count == " );
sblMsg.Append( sl2.Count );
Console.Error.WriteLine( sblMsg.ToString() );
}
for (i=0; i<100; i++)
{
++iCountTestcases;
j = i+100;
if (!sl2.ContainsKey ((int)j))
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_0dj! - ContainsKey failed at i == " );
sblMsg.Append( i );
示例12: runTest
public virtual bool runTest()
{
Console.Error.WriteLine( "Co4332IndexOfValue runTest() started." );
String strLoc="Loc_000oo";
StringBuilder sblMsg = new StringBuilder( 99 );
int iCountErrors = 0;
int iCountTestcases = 0;
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder( 99 );
StringBuilder sbl4 = new StringBuilder( 99 );
StringBuilder sblWork1 = new StringBuilder( 99 );
String str5 = null;
String str6 = null;
String str7 = null;
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
int[] in4a = new int[9];
int nCapacity = 100;
bool bol = false;
int i = 0;
int j = 0;
try
{
LABEL_860_GENERAL:
do
{
strLoc="100cc";
iCountTestcases++;
sl2 = new SortedList( this );
iCountTestcases++;
if ( sl2 == null )
{
Console.WriteLine( strTest+ "E_101" );
Console.WriteLine( strTest+ "SortedList creation failure" );
++iCountErrors;
break;
}
iCountTestcases++;
if ( sl2.Count != 0 )
{
Console.WriteLine( strTest+ "E_102" );
Console.WriteLine( strTest+ "New SortedList is not empty" );
++iCountErrors;
}
iCountTestcases++;
try
{
j = sl2.IndexOfValue((String)null);
if (j != -1)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_39re! - should return -1..." );
Console.Error.WriteLine( "returned: " + j );
}
}
catch (Exception exc)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_59f! - " + exc.ToString() );
}
iCountTestcases++;
j = sl2.IndexOfValue("No_Such_Val");
if (j != -1)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_658d! - should return -1..." );
Console.Error.WriteLine( "returned: " + j );
}
strLoc="100.5cc";
sl2.Add ("Key_0", null);
j = sl2.IndexOfValue(null);
if (j == -1)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_47d! - should not return -1..." );
}
strLoc="100.6cc";
sl2.Add ("Key_1", "Val_Same");
sl2.Add ("Key_2", "Val_Same");
try
{
j = sl2.IndexOfValue("Val_Same");
if (j != 1)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_985g! - IndexOf failed to return first occurrence..." );
Console.Error.WriteLine( "returned: " + j );
}
}
catch (Exception exc)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_095! - " + exc.ToString() );
}
strLoc="100.7cc";
sl2.Clear();
strLoc="Loc_141aa";
for (i=0; i<100; i++)
//.........这里部分代码省略.........
示例13: TestGetEnumeratorBasic
public void TestGetEnumeratorBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
//
SortedList sl2 = null;
IDictionaryEnumerator dicen = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
int i3 = 0;
int i2 = 0;
int i = 0;
int j = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// Testcase: Set - null key, ArgExc expected
Assert.Throws<ArgumentNullException>(() =>
{
sl2[null] = 0;
});
Assert.Equal(0, sl2.Count);
// Testcase: Set - null val
sl2[(object)100] = (object)null;
Assert.Equal(1, sl2.Count);
// Testcase: vanila Set
sl2[(object)100] = 1;
Assert.Equal(1, sl2.Count);
sl2.Clear();
Assert.Equal(0, sl2.Count);
// Testcase: add key-val pairs
for (i = 0; i < 100; i++)
{
sl2.Add(i + 100, i);
}
Assert.Equal(100, sl2.Count);
for (i = 0; i < 100; i++)
{
j = i + 100;
Assert.True(sl2.ContainsKey((int)j));
Assert.True(sl2.ContainsValue(i));
object o2 = sl2[(object)(j)]; //need to cast: Get (object key)
Assert.NotNull(o2);
i2 = (int)o2;
i3 = (int)sl2.GetByIndex(i); //Get (index i)
Assert.False((i3 != i) || (i2 != i));
// testcase: GetEnumerator
dicen = (IDictionaryEnumerator)sl2.GetEnumerator();
// Boundary for Current
Assert.Throws<InvalidOperationException>(() =>
{
object throwaway = dicen.Current;
}
);
j = 0;
// go over the enumarator
while (dicen.MoveNext())
{
// Current to see the order
i3 = (int)dicen.Value;
Assert.True(j.Equals(i3));
// Current again to see the same order
i3 = (int)dicen.Value;
Assert.Equal(i3, j);
j++;
}
// Boundary for Current
Assert.Throws<InvalidOperationException>(() =>
{
object throwaway = dicen.Current;
//.........这里部分代码省略.........
示例14: TestIndexOfValueBasic
public void TestIndexOfValueBasic()
{
StringBuilder sblMsg = new StringBuilder(99);
//
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
string s1 = null;
string s2 = null;
string s3 = null;
string s4 = null;
int i = 0;
int j = 0;
//
// Constructor: Create SortedList using this as IComparer and default settings.
//
sl2 = new SortedList(this);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList is empty.
Assert.Equal(0, sl2.Count);
// with null - should return -1
// null val
j = sl2.IndexOfValue((string)null);
Assert.Equal(-1, j);
// invalid val - should return -1
j = sl2.IndexOfValue("No_Such_Val");
Assert.Equal(-1, j);
// null is a valid value
sl2.Add("Key_0", null);
j = sl2.IndexOfValue(null);
Assert.NotEqual(-1, j);
// first occurrence check
sl2.Add("Key_1", "Val_Same");
sl2.Add("Key_2", "Val_Same");
j = sl2.IndexOfValue("Val_Same");
Assert.Equal(1, j);
sl2.Clear();
// Testcase: add few key-val pairs
for (i = 0; i < 100; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_");
sblMsg.Append(i);
s2 = sblMsg.ToString();
sl2.Add(s1, s2);
}
//
// Testcase: test IndexOfVal
//
for (i = 0; i < sl2.Count; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_"); //key
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_"); //value
sblMsg.Append(i);
s2 = sblMsg.ToString();
// now use IndexOfKey and IndexOfVal to obtain the same object and check
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1)); //Get the index of this key and then get object
s4 = (string)sl2.GetByIndex(sl2.IndexOfValue(s2)); //Get the index of this val and then get object
Assert.True(s3.Equals(s4));
// now Get using the index obtained thru IndexOfKey () and compare it with s2
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1));
Assert.True(s3.Equals(s2));
}
//
// Remove a key and then check
//
sblMsg.Length = 0;
sblMsg.Append("key_50");
s1 = sblMsg.ToString();
//.........这里部分代码省略.........
示例15: calcPrognoz
public void calcPrognoz()
{
if (PArr.Count % 24 != 0) {
int addCnt=24 - PArr.Count % 24;
for (int i=0; i < addCnt; i++) {
DateTime last=PArr.Last().Key;
PArr.Add(last.AddMinutes(30), PArr[last]);
}
}
SortedList<int,double>prevDataRashodArray=new SortedList<int, double>();
SortedList<int,double>prevDataNBArray=new SortedList<int, double>();
SortedList<int,double>prevDataVBArray=new SortedList<int, double>();
prognoz=new SortedList<DateTime, double>();
int index=0;
double k=0;
foreach (DateTime date in FirstData.Keys) {
prevDataRashodArray.Add(index, FirstData[date].Q);
prevDataNBArray.Add(index, FirstData[date].NB);
prevDataVBArray.Add(index, FirstData[date].VB);
k = FirstData[date].Q / RashodTable.getStationRashod(FirstData[date].P, FirstData[date].VB - FirstData[date].NB, RashodCalcMode.avg);
index++;
}
napors=new SortedList<DateTime, double>();
rashods = new SortedList<DateTime, double>();
double napor=prevDataVBArray.Last().Value - prevDataNBArray.Last().Value;
foreach (KeyValuePair<DateTime,double>de in pArr) {
napors.Add(de.Key, napor);
}
foreach (KeyValuePair<DateTime,double> de in PArr) {
double rashod=IsQFakt ? de.Value : RashodTable.getStationRashod(de.Value, napors[de.Key], RashodCalcMode.avg) * k;
rashods.Add(de.Key, rashod);
prognoz.Add(de.Key, 0);
}
//prognoz.Add(rashods.First().Key.AddMinutes(-30), prevDataNBArray[4]);
double currentNapor=napors.First().Value;
SortedList<DateTime,double> dataForPrognoz=new SortedList<DateTime, double>();
SortedList<DateTime,double> naporsForPrognoz=new SortedList<DateTime, double>();
for (int indexPoint=0; indexPoint < pArr.Keys.Count; indexPoint++) {
DateTime Key=pArr.Keys[indexPoint];
dataForPrognoz.Add(Key, pArr[Key]);
naporsForPrognoz.Add(Key, napors[Key]);
if (dataForPrognoz.Count == 24) {
SortedList<int,double> outputVector=new SortedList<int, double>();
for (int step=0; step <= 3; step++) {
SortedList<int, double> inputVector=new SortedList<int, double>();
inputVector[0] = DatePrognozStart.Year;
inputVector[1] = DatePrognozStart.DayOfYear;
inputVector[2] = T;
inputVector[3] = prevDataVBArray[1];
inputVector[4] = prevDataVBArray[2];
inputVector[5] = prevDataVBArray[3];
inputVector[6] = prevDataVBArray[4];
inputVector[7] = prevDataRashodArray[1];
inputVector[8] = prevDataRashodArray[2];
inputVector[9] = prevDataRashodArray[3];
inputVector[10] = prevDataRashodArray[4];
for (int i=0; i < 24; i++) {
double rashod=0;
if (!IsQFakt) {
rashod = RashodTable.getStationRashod(pArr[dataForPrognoz.Keys[i]], naporsForPrognoz[dataForPrognoz.Keys[i]], RashodCalcMode.avg)*k;
} else {
rashod = rashods[dataForPrognoz.Keys[i]];
}
rashods[dataForPrognoz.Keys[i]] = rashod;
inputVector[i + 11] = rashod;
}
inputVector[35] = prevDataNBArray[1];
inputVector[36] = prevDataNBArray[2];
inputVector[37] = prevDataNBArray[3];
inputVector[38] = prevDataNBArray[4];
outputVector = nnet.calc(inputVector);
for (int i=0; i < outputVector.Count; i++) {
prognoz[dataForPrognoz.Keys[i]] = outputVector[i];
}
for (int i=0; i < 24; i++) {
naporsForPrognoz[dataForPrognoz.Keys[i]] = prevDataVBArray[4] - prognoz[dataForPrognoz.Keys[i]];
napors[dataForPrognoz.Keys[i]] = naporsForPrognoz[dataForPrognoz.Keys[i]];
}
}
for (int i=0; i <= 4; i++) {
prevDataNBArray[i] = prognoz[dataForPrognoz.Keys[19 + i]];
prevDataRashodArray[i] = rashods[dataForPrognoz.Keys[19 + i]];
}
dataForPrognoz.Clear();
//.........这里部分代码省略.........