public void ReadNullValueLabels() { using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read)) { SpssVariable var = docRead.Variables[3]; Assert.False(var.GetValueLabels().Any()); } }
public void ReadLabel() { using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read)) { SpssVariable var = docRead.Variables[0]; Assert.Equal("on butter", var.Label); } }
public void ReadNullLabel() { using (SpssDataDocument docRead = SpssDataDocument.Open(TestBase.GoodFilename, SpssFileAccess.Read)) { SpssVariable var = docRead.Variables[3]; Assert.Equal(string.Empty, var.Label); } }
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); } }
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); } }
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)); } }
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."); } }
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); } }
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); } }
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); } }
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); } }
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; } }