コード例 #1
0
 public void ReadNullValueLabels()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[3];
         Assert.False(var.GetValueLabels().Any());
     }
 }
コード例 #2
0
 public void ReadLabel()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[0];
         Assert.Equal("on butter", var.Label);
     }
 }
コード例 #3
0
 public void ReadNullLabel()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssVariable var = docRead.Variables[3];
         Assert.Equal(string.Empty, var.Label);
     }
 }
コード例 #4
0
 public void GetLongStringValueLabels()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssStringVariable var = (SpssStringVariable)docRead.Variables["longStr"];
         // long strings can never have value labels
         Assert.Equal(0, var.ValueLabels.Count);
     }
 }
コード例 #5
0
 public void ReadDecimalPlaces()
 {
     using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read))
     {
         SpssNumericVariable var = docRead.Variables[0] as SpssNumericVariable;
         Assert.NotNull(var); // First variable expected to be numeric.
         Assert.Equal(2, var.WriteDecimal);
     }
 }
コード例 #6
0
 public void SetStringTooLong()
 {
     using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
     {
         SpssStringVariable var = (SpssStringVariable)docAppend.Variables["charLabels"];
         Debug.Assert(var.Length == 8);
         SpssCase row = docAppend.Cases.New();
         Assert.Throws <ArgumentOutOfRangeException>(() => row["charLabels"] = new string('a', var.Length + 1));
     }
 }
コード例 #7
0
 public void OpenExistingDocumentForAppend()
 {
     using (SpssDataDocument doc = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
     {
         Assert.Equal(SpssFileAccess.Append, doc.AccessMode);
         Assert.False(doc.IsClosed, "Newly opened document claims to be closed.");
         Assert.Equal(TestBase.AppendFilename, doc.Filename);
         Assert.False(doc.IsAuthoringDictionary, "Cannot be authoring dictionary when appending data.");
     }
 }
コード例 #8
0
 private static void CreateExampleDocument()
 {
     using (SpssDataDocument doc = SpssDataDocument.Create("example.sav")) {
         CreateMetaData(doc);
         CreateData(doc);
     }
     Console.WriteLine("Examine example.sav for the results.");
     Console.WriteLine("SPSS file reading demo:");
     using (SpssDataDocument doc = SpssDataDocument.Open(GetFileName(), SpssFileAccess.Read)) {
         PrintMetaData(doc);
         PrintData(doc);
     }
 }
コード例 #9
0
ファイル: DataManipulator.cs プロジェクト: bmla/SW9_Project
        public static void ReadSpssFile()
        {
            using (var doc = SpssDataDocument.Open("t.sav", SpssFileAccess.Append)) {
                SpssNumericVariable accuracy = new SpssNumericVariable {
                    Name             = $"Accuracy",
                    Label            = $"Distance in pixels from target",
                    MeasurementLevel = MeasurementLevelCode.SPSS_MLVL_RAT
                };
                doc.Variables.Add(accuracy);

                SpssStringVariable var = (SpssStringVariable)doc.Variables["someLabel"];

                SpssCase row = doc.Cases.New();
                row[$"Accuracy"] = new string('a', var.Length + 1);
            }
        }
コード例 #10
0
        public void SetMissingValueDateByNull()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex       = row.Position;
                row["dateVar"] = null;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                DateTime?val = (DateTime?)row["dateVar"];
                Assert.False(val.HasValue);
            }
        }
コード例 #11
0
        public void SetMissingValueNumeric()
        {
            int rowIndex;

            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Append))
            {
                SpssCase row = docAppend.Cases.New();
                rowIndex   = row.Position;
                row["num"] = double.NaN;
                row.Commit();
            }
            using (SpssDataDocument docAppend = SpssDataDocument.Open(TestBase.AppendFilename, SpssFileAccess.Read))
            {
                SpssCase row = docAppend.Cases[rowIndex];
                double   val = (double)row["num"];
                Assert.Equal(double.NaN, val);
            }
        }
コード例 #12
0
ファイル: TestBase.cs プロジェクト: pgaske/SPSS.NET
 public TestBase()
 {
     try
     {
         docRead   = SpssDataDocument.Open(GoodFilename, SpssFileAccess.Read);
         docAppend = SpssDataDocument.Open(AppendFilename, SpssFileAccess.Append);
         if (File.Exists(DisposableFilename))
         {
             File.Delete(DisposableFilename);
         }
         docWrite = SpssDataDocument.Create(DisposableFilename);
     }
     catch
     {
         docRead?.Dispose();
         docAppend?.Dispose();
         docWrite?.Dispose();
         throw;
     }
 }